Reputation: 141
I am trying to write a SQL query and that works, but the stored procedure is not working when I try with parameters.
Example :
select *
from Table1
where Name = 'BEST People' // this works
// this does not show any rows
declare @Name nvarchar(128)
set @Name= 'BEST People'
select *
from Table1
where Name = @Name
Even when I try with a stored procedure, it does not work.
Upvotes: 1
Views: 58
Reputation: 171
Depending on your column collation String Comparison Work Specify Your Question Like This
Here's how you would check your column collation:
DECLARE @TableId INT
SELECT @TableId=id FROM sys.sysobjects
WHERE xtype='U' AND name='Table1'; --Your table name here
SELECT name, collation_name FROM sys.columns
WHERE object_id=@TableId AND name=N'Name'; --Your column name here
Upvotes: 2
Reputation: 21766
You need to cast the string to NVARCHAR
:
declare @Name nvarchar(128)
set @Name= N'BEST People'
select * from Table1 where Name = @Name
Without the N
it will be a VARCHAR
Upvotes: 0