Hi all I am trying to use an IN clause base on a condition. I don’t want 2 separate SQL statements and was hoping for an inline solution. I want to say, if the string is blank then don’t apply the IN query, however if it isn’t then use it. I know I can do an IF statement but I think that smells but unsure of another way of doing it? Googling around showed that the IN doesn’t support case keyword…
Thanks in advance, Onam.
declare @PartStockID nvarchar(50)
set @PartStockID = '32919,40335'
select top 10 * from PMS_PartStock
where
(@PartStockID != '' AND PartStockID in (SELECT ID FROM dbo.Split_List_Int(@PartStockID)) OR PMS_PartStock.PartStockID = PMS_PartStock.PartStockID )
change
ANDtoORand!=to=