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

  • 相关阅读:
    CBP是什么?
    编码器变换及量化的流程?
    CABAC与CAVLC有什么区别?
    如何在JM8.6编码端提取QDCT?
    宏块都有哪些类型?
    H264帧间预测流程?
    H264子宏块的划分有哪些?
    H264提供了哪些帧内预测?
    加强预测编码?
    centos7 下通过nginx+uwsgi部署django应用
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3957806.html
Copyright © 2011-2022 走看看