我有一个简单的选择和两个参数。
@first
@second
SELECT ProductID, ProductName, ProductType, ProductLevel
FROM ProductTable
如果两个参数都没有值,则在执行过程时,我需要执行此部分:
WHERE ProductType = 1 AND ProductLevel = 1
如果我有第一个参数的值,则:
WHERE ProductType = 2 AND ProductName LIKE @first + '%'
如果我有第二个参数的值,那么:
WHERE ProductType =3 AND ProductName LIKE @second + '%'
有人可以帮助我实现此逻辑并创建有效的存储过程吗?
答案 0 :(得分:4)
如果我理解正确,那么您需要下一个“ WHERE”声明:
WHERE
(@first IS NULL AND @second IS NULL AND ProductType = 1 AND ProductLevel = 1)
OR
(@first is NOT NULL AND ProductType = 2 AND ProductName LIKE @first + '%')
OR
(@second is NOT NULL AND ProductType = 3 AND ProductName LIKE @second + '%')
答案 1 :(得分:1)
您应该尝试IN格式:
>>> online_dict = {sub[0]: sub for sub in Online}
>>> online_dict.update(newsub_dict)
>>> list(online_dict.values())
[['Robot1', '30.9', 'Sending', '440'],
['Robot3', 'has no replacement'],
['Robot2', '50'],
['Robot4', 'new entry']]
答案 2 :(得分:1)
添加另一种方式,
(!!)
如果逻辑看起来更大,我们可以通过这种方式实现。