zoukankan      html  css  js  c++  java
  • SQL update 关联更改,内部需要引用表名

    select A.Id,A.Email,(
    select C.Email from [nopCommerce].[dbo].[Customer] C 
    left join [nopCommerce].[dbo].CustomerAddresses CA 
    on C.Id=CA.Customer_Id where A.Id=CA.Address_Id) as 'Email2' from [nopCommerce].[dbo].[Address] A

    如此有效。

    update [nopCommerce].[dbo].[Address] set Email=(
    select C.Email from [nopCommerce].[dbo].[Customer] C
    left join [nopCommerce].[dbo].CustomerAddresses CA 
    on C.Id=CA.Customer_Id where Id=CA.Address_Id) 

    如此无效 数据是改了,但完全不是要的结果

    update [nopCommerce].[dbo].[Address] set Email=(
    select C.Email from [nopCommerce].[dbo].[Customer] C
    left join [nopCommerce].[dbo].CustomerAddresses CA 
    on C.Id=CA.Customer_Id where  [nopCommerce].[dbo].[Address] .Id=CA.Address_Id) 

    只有在内部连接上

    改为[nopCommerce].[dbo].[Address] .Id 才有效


    DECLARE @a TABLE (Id INT, NewEmail NVARCHAR(200))
    --INSERT INTO @a( Id, NewEmail)VALUES(1,'abc')

    INSERT INTO @a( Id, NewEmail)
    select A.Id,(
    select C.Email from [nopCommerce].[dbo].[Customer] C
    left join [nopCommerce].[dbo].CustomerAddresses CA
    on C.Id=CA.Customer_Id where A.Id=CA.Address_Id) as 'Email2' from [nopCommerce].[dbo].[Address] A


    update [nopCommerce].[dbo].[Address] set Email=(
    select T.NewEmail from @a T where [nopCommerce].[dbo].[Address].Id=T.Id)

    update [nopCommerce].[dbo].[Address] set Email=(
    select C.Email from [nopCommerce].[dbo].[Customer] C
    left join [nopCommerce].[dbo].CustomerAddresses CA
    on C.Id=CA.Customer_Id where Id=CA.Address_Id)

    select A.Id,A.Email,(
    select C.Email from [nopCommerce].[dbo].[Customer] C
    left join [nopCommerce].[dbo].CustomerAddresses CA
    on C.Id=CA.Customer_Id where A.Id=CA.Address_Id) as 'Email2' from [nopCommerce].[dbo].[Address] A

  • 相关阅读:
    video兼容ie,ckplayer网页播放器
    边框在2个边,不重叠不接触的情况下是梯形。
    【Unity】关于屏幕自适应的思路
    【Unity】鼠标指向某物体,在其上显示物体的名字等等等等信息
    【C#】关于左移/右移运算符的使用
    【Unity】鼠标点选物体
    Python time和datetime模块
    Python 模块之间的调用
    SaltStack 使用pillar安装配置管理zabbix
    SaltStack 实践课程一
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3957806.html
Copyright © 2011-2022 走看看