question

aRookieBIdev avatar image
aRookieBIdev asked

problem with date in where condition

I have a table with dateofbirth column and a name column. Dateofbirth is of type date and name is a nvarchar. when i query the table select * from dbo.Table where Name = 'ss' and DateofBirth = '2011-12-03' i get the result but when i use a stored procedure to pass in the parameters , i dont get any data. Can some one explain me what i am doing wrong???!!1 SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO ALTER proc [dbo].[SearchUser](@Name nvarchar(48),@DateofBirth date) as begin select * from dbo.Table where DateofBirth= @DateofBirth and PatientName like '%@PatientName%' end
sql-server-2008t-sqlstored-procedures
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Magnus Ahlkvist avatar image Magnus Ahlkvist commented ·
How do you pass the parameter - how's your call to the stored procedure looking?
0 Likes 0 ·

1 Answer

·
WilliamD avatar image
WilliamD answered
Your problem is here: and PatientName like '%@PatientName%' You need to separate the percent from the variable and concatenate the string: and PatientName like '%' + @PatientName + '%'
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Magnus Ahlkvist avatar image Magnus Ahlkvist commented ·
+1. Well spotted.
0 Likes 0 ·
Fatherjack avatar image Fatherjack ♦♦ commented ·
Nice spot William. Waiting for @mrs_fatherjack to comment on the new avatar... ;)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.