1
select (select code from SC_StockItem where StockItemID = a.StockItemID)
from SC_StockItemVariantSetAttribValue a
inner join SC_StockItemVariantSetAttribValue a2 on a.StockItemID = a2.StockItemID
and a2.VariantSetAttribValueID = 18
inner join SC_StockItemVariantSetAttribValue a3 on a2.StockItemID = a3.StockItemID
and a3.VariantSetAttribValueID = 12
where a.VariantSetAttribValueID = 26

我希望执行上面的查询。类似于以下的行:

inner join SC_StockItemVariantSetAttribValue a2 on a.StockItemID = a2.StockItemID
    and a2.VariantSetAttribValueID = 18

将相应地添加从另一个查询返回的行数。有没有办法可以在 TSQL 函数中添加这些行?

4

1 回答 1

0

尝试添加条件以join使此部分固定,而不是动态:

inner join SC_StockItemVariantSetAttribValue a2 on (a.StockItemID=a2.StockItemID
and a2.VariantSetAttribValueID = 19 
and @anotherQueryCount > 0)  --here you check your additional rule  

如果条件为真,加入将起作用。

于 2013-07-11T14:12:45.097 回答