I have following query used by c# program:
var names = string.Join(",", activeNames.Select(n => string.Format("'{0}'", n)).ToArray());
var query = @"SELECT * FROM TableA WHERE NOT Name IN (" + names + ")";
The above query works as long as there is value in names like if name = 'Ken', 'John' this works. But if name is empty query looks like this:
SELECT * FROM TableA WHERE NOT Name IN ()
which is invalid syntax how can i make this query work?
I can use two seperate queries like:
SELECT * FROM TableA
//if name is empty
or above query if name has values. But is this right way to approch this?