Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,The thing is that if the @Tags IS NULL don't condider the userID by assinging 1 = 1if @Tags IS NOT NULL then assign Users.UserID = Items.UserIDbut the Items.UserID is having some other value.DECLARE @Tags VARCHAR(10)DECLARE @UserNames VARCHAR(10)BEGIN SET @UserNames = 'babu' SET @Tags = NULL SELECT Items.DateAdded, Items.Item , ItemTags.Tag FROM dbo.Items INNER JOIN dbo.ItemTags ON Items.ItemID = ItemTags.ItemID -- INNER JOIN dbo.Users ON Users.UserID = Items.UserID INNER JOIN dbo.Users ON CASE WHEN @Tags IS NOT NULL THEN Users.UserID ELSE 1 END = Items.UserID WHERE ','+@UserNames+',' LIKE '%,'+Users.UserName+',%'ENDThanks in advance.