hello temp11
hello temp11

Reputation: 141

Passing parameter to a SQL Server stored procedure

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

Answers (2)

satish
satish

Reputation: 171

Depending on your column collation String Comparison Work Specify Your Question Like This

enter image description here

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

View Collation Information

Upvotes: 2

Alex
Alex

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

Related Questions