开发者

SQL detecting null value and change query

i am using c# and mssql. i send parameters from c# to sql and execute a query but sometimes it comes null values. i m using sql like function. it is g开发者_高级运维reat for string values but has problems with bool. for example bool b = NULL query executes like that: .... WHERE B LIKE '%%' and it never returns a value. i want to detect null value and change query if b is null the query must be like that ...... WHERE B IS NOT NULL i could change this in c# code but there are some other parameters like that it could be easier in sql if it is possible

thanks


SQL server supports the standard SQL COALESCE function; try wrapping your boolean values in a coalesce call, e.g. WHERE COALESCE(bool_value, '') LIKE '%%'


Use parameterized queries and all of this is taken care of for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜