gpt4 book ai didi

sql-server - 为什么不能在select语句中使用if语句?有人知道另一种方法吗?

转载 作者:行者123 更新时间:2023-12-03 10:01:52 24 4
gpt4 key购买 nike

Select b.ItemKey, a.CatKey, a.ParentKey, a.CatName, g.ItemID, c.UserFld1, c.UserFld3, c.UserFld5, f.UOMID, e.SizeValue
From dbo.timWebCategory a Inner JOIN
dbo.timWebCategoryItem b ON a.CatKey = b.CatKey Inner JOIN
mas500_app.dbo.timItem c ON b.ItemKey = c.ItemKey Inner JOIN
dbo.cpsIMItemDetails d ON c.ItemKey = d.ItemKey Inner JOIN
dbo.timItemSize e ON c.ItemKey = e.ItemKey Left JOIN
dbo.timVolumeUOM f ON e.VolUOMKey = f.VolUOMKey Left JOIN
mas500_app.dbo.vWebItem g ON c.ItemKey = g.ItemKey
Where a.Catkey = @Key
AND d.IntFlg = 1
If @color is not Null
Begin
AND c.UserFld1 = @color
End
Order By f.UOMID, e.SizeValue**


返回此:
关键字“ AND”附近的语法不正确。

最佳答案

试试看...

Select b.ItemKey, a.CatKey, a.ParentKey, a.CatName, g.ItemID, c.UserFld1, c.UserFld3, c.UserFld5, f.UOMID, e.SizeValue
From dbo.timWebCategory a Inner JOIN
dbo.timWebCategoryItem b ON a.CatKey = b.CatKey Inner JOIN
mas500_app.dbo.timItem c ON b.ItemKey = c.ItemKey Inner JOIN
dbo.cpsIMItemDetails d ON c.ItemKey = d.ItemKey Inner JOIN
dbo.timItemSize e ON c.ItemKey = e.ItemKey Left JOIN
dbo.timVolumeUOM f ON e.VolUOMKey = f.VolUOMKey Left JOIN
mas500_app.dbo.vWebItem g ON c.ItemKey = g.ItemKey
Where a.Catkey = @Key
AND d.IntFlg = 1
AND (@color = c.UserFld1 OR @color is null)
Order By f.UOMID, e.SizeValue**

关于sql-server - 为什么不能在select语句中使用if语句?有人知道另一种方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7033882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com