I know this question was asked many times, but i am not able to find a solution for it
This is my code
string query = @"SELECT *
WHERE (respondCode IS @respondCode)
and (sentOn > '08/26/2016')
//string query = "select * from SMSMessage";
SqlConnection con = new SqlConnection(Utilities.getConnectionString());
SqlCommand cmd = new SqlCommand(query, con);
syntax error near @responseCode
responseCode is NULL
I guess you want this
Where (respondCode = @respondCode or @respondCode is null) and sentOn > '08/26/2016'
When a value is passed to
@respondCode parameter the records will be filter based on
sentOn > '08/26/2016'.
When nothing is passed to
@respondCode parameter (ie)
NULL, then records will be filtered only based on
sentOn > '08/26/2016'
As mentioned in comments by Steve, If you need records only when
NULL then no need of that variable just hardcode the
NULL condition in
Where respondCode is null and sentOn > '08/26/2016'