您好我想知道如果我可以的,如果在下面的查询语句中使用..我可以在此查询中使用IF语句吗?
select * from Table
Where Field1 = 'john' and
if Field2 = 'Mike'
Then(dbo.StateId(gp.SiD) Like '%' + @StateName +'%'))
Else Nothing**
感谢
您好我想知道如果我可以的,如果在下面的查询语句中使用..我可以在此查询中使用IF语句吗?
select * from Table
Where Field1 = 'john' and
if Field2 = 'Mike'
Then(dbo.StateId(gp.SiD) Like '%' + @StateName +'%'))
Else Nothing**
感谢
号工作
SELECT *
FROM Table
WHERE Field1 = 'john'
AND (Field2 <> 'Mike'
OR dbo.StateId(gp.SiD) LIKE '%' + @StateName + '%')
(您的示例代码不会向我明确什么应该h澳鹏如果Field2
是NULL
)
我觉得SELECT/CASE会为你正在尝试做
select *
from Table
Where Field1 = 'john'
and case when Field2 = 'Mike'
Then (dbo.StateId(gp.SiD) Like '%' + @StateName +'%'))
Else (true or false based on inclusion) end
是的,你可以使用,在SQL查询,但是查询的语法statments可以依赖的数据库(MySQL和甲骨文,...)。 – ssoler 2011-03-03 15:24:20
@ssoler - 我认为是SQL服务器(来自'dbo.') – 2011-03-03 15:25:26