2

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 great 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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.