Select SQL with nullable integer variable and "in" at the where clause in asp dataset

100 Views Asked by At

I have a SQL query like bellow at the dataset in asp, naming "GetData":

select * 
from TABLE1 
where (TABLE1.ID in (select RecID from TABLE2 where TABLE2.RecID = @RecID))
   or (@RecID is null)

But when I use this method to retrieve data from database:

?int RecID;
GetData(RecID);

I get an error:

the best overloaded method match for datasettableadapters.GetData(int)has some invalid arguments

So it doesn't accept nullable arguments for @RecID, but when I change the SQL statement to this:

select * 
from TABLE1 
where (TABLE1.ID in (select RecID from TABLE2 where TABLE2.RecID = @RecID))

it accepts the nullable RecID argument.

But I want to retrieve all data from TABLE1 (without its where clause) when the argument @RecID is NULL.

0

There are 0 best solutions below