I have a simple select to bring back records according to status:SELECT ID, CommentFROM myTableWHERE StatusID = @StatusID OR @StatusID IS NULL OR @StatusID = -1
Straight forward, the param @StatusID being sent in is ignored if it's NULL or -1 then it will bring back all records no matter the status.Otherwise it brings back only the records with the requested status.What about a user defined table type?CREATE TYPE [dbo].[int_list_tbltype] AS TABLE( [ID] INT NOT NULL)GO
Then the params being sent into the stored procedure are: @StatusID INT, @POSLst dbo.int_list_tbltype READONLY
Easy to use if it's populated.SELECT ID, CommentFROM myTableWHERE (StatusID = @StatusID OR @StatusID IS NULL OR @StatusID = -1)AND(POSID IN (SELECT ID FROM @POSLst))
I've been trying to find a way to add this to the where clause so it will ignore it if it's empty. If it's empty, bring back all POSID's and if it's not empty, do the IN statement.Sure, an if statement with two sql statements would work but the actual sql statement is quite long.Thanks for any input.