Sagar
Sagar

Reputation: 15

Can I use this type in query in SQL Server

ALTER Procedure [dbo].[SELECT_STATUS_OF_MAILREPORT]
    (@ID int, @Name varchar(15))
As 
Begin
    Select ID, NAME, CONTACT, EMAIL, SUBJECT, DISCRIPTION 
    From dbo.ProInfo
    Where ID = 45 and Name Like '%@Name%'
End

Upvotes: 0

Views: 30

Answers (1)

Spock
Spock

Reputation: 4900

No... Your where statement is using a literal to compare to name... You need to change it to this.

ALTER Procedure [dbo].[SELECT_STATUS_OF_MAILREPORT](@ID int,@Name varchar(15))
As 
Begin
    Select ID,NAME, CONTACT, EMAIL, SUBJECT, DISCRIPTION 
    From dbo.ProInfo
    WHERE ID=45 and Name Like '%' + @Name + '%'
End

Note: for this to work, @Name can not be null...

Upvotes: 3

Related Questions