如果SQL Server中没有使用EXISTS引入子查询,则只能在选择列表中指定一个表达式

如果SQL Server中没有使用EXISTS引入子查询,则只能在选择列表中指定一个表达式,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,当我通过select query和store在一个变量中给出条件时,在该条件下,我给出了insert查询,此时问题就来了 这是我的问题 create table #temp ( productid int ) --Insert into #temp Insert into #temp select Product.Id from Product left join mysql_abc_Product on mysql_abc_Product.Product

当我通过select query和store在一个变量中给出条件时,在该条件下,我给出了insert查询,此时问题就来了

这是我的问题

create table #temp
(
    productid int
) 

--Insert into #temp
Insert into #temp
    select Product.Id 
    from Product 
    left join mysql_abc_Product on mysql_abc_Product.ProductId = Product.ID
    where mysql_abc_Product.ProductId is NULL

Declare @maxCount int = (select count(productId) from #temp)

WHILE(@i <= @maxCount)
BEGIN
    select * from #temp

    declare @ModelID int
    SET @ModelID = (select DISTINCT tmp.ProductId, s.Id, l.Id 
                    from Language l, Store s, #temp tmp, Product p 
                    left join mysql_abc_Product isp on isp.ProductId = p.Id  
                    where isp.Id is NULL 
                      and p.Deleted = 'False' 
                       or p.Published = 'True' 
                       or VisibleIndividually = 'True')

    if(@ModelID > 0)
        Insert into mysql_abc_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId, LanguageId) 
            select DISTINCT 
                tmp.ProductId, 1, 0, GETDATE(), s.Id, l.Id 
            from  
                Language l, Store s, #temp tmp, Product p 
            left join 
                mysql_abc_Product isp on isp.ProductId = p.Id  
            where 
                isp.Id is NULL 
    else
        Insert into mysql_abc_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId, LanguageId) 
            select DISTINCT 
                tmp.ProductId, 1, 0, GETDATE(), s.Id, l.Id 
            from  
                Language l, Store s, #temp tmp, Product p 
            left join 
                mysql_abc_Product isp on isp.ProductId = p.Id  
            where 
                isp.Id is NULL 

        SET @i  = @i  + 1
    END

    drop table #temp
END
-20多年前,在ANSI-92 SQL标准中,旧样式的逗号分隔表列表样式被正确的ANSI连接语法所取代,因此不鼓励使用它。你绝对不应该把它们混在一起20多年前,在ANSI-92 SQL标准中,旧样式的逗号分隔表列表样式被正确的ANSI连接语法所取代,因此不鼓励使用它。你绝对不应该把它们混在一起!!