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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select problems

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2008-04-10 : 10:15:23
Here is my simple (at the moment)stored procedure.

SELECT * FROM tblPHCR_Register
WHERE Reg_Surname like '%'+@Surname+'%' and Reg_HomeAdd1 like '%'+@HomeAdd+'%' and
Reg_HomePCode like '%'+@HomePcode+'%'

However, I want to be able to leave any one of the fields blank and still search on the data entered. In the database an empty field maybe null or zero length string. How can I do this ?

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-04-10 : 10:17:04
WHERE (Reg_Surname like '%'+@Surname+'%' or @surname is null )and (Reg_HomeAdd1 like '%'+@HomeAdd+'%' or @homeadd is null) and
(Reg_HomePCode like '%'+@HomePcode+'%' or @homePcode is null)


Em
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2008-04-10 : 10:31:35
Thanks - obvious when you showed me how
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-04-10 : 11:46:17
http://sommarskog.se/dyn-search.html


elsasoft.org
Go to Top of Page
   

- Advertisement -