I have a table called UserList which has UserName and UserPassword columns. When I query as below, it Works and returns the right data.
SELECT * FROM dbo.UserList WHERE UserName = 'aliserin'
But when I try it as below, it doesn't give me any result. It just returns empty. It doesn't give an error, but I really didn't understand the reason. It is a local database if it matters.
declare
@UserName as NVARCHAR
SET
@UserName = 'aliserin'
SELECT * FROM dbo.UserList WHERE UserName = @UserName
When I try the same code on UserId constraint as below, it works. Does anyone has any idea why?
DECLARE @UserName1 AS NVARCHAR
SET @UserName1 = 2
SELECT * FROM dbo.UserList WHERE UserId = @UserName1