Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2014-07-25 : 20:50:56
|
hiThere is something wrong with my where statement. It returns results even though i specify a so called empty string to the stored proc.How should i prevent returning result when is empty? Thanks a lot here is my code:Create proc TestEmployee_Search@searchnameemail as nvarchar(50)asSet NoCount OnSELECT [FirstName] ,[LastName] ,[Email] FROM [dbo].[Account] where '' + ([FirstName] + ' ' + [LastName] + ' ' + [Email]) + '' like '%' + '' + @searchnameemail + '' + '%'Exec TestEmployee_Search '' |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-07-25 : 21:23:51
|
[code]LIKE '%' + NULLIF ( @searchnameemail , '') + '%'[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2014-07-25 : 21:34:26
|
Thanks KH. It works |
|
|
|
|
|