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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-04-13 : 07:20:25
|
| Laurie writes "I am running a SQL query:SELECT dbo.StatMain.SMIndex, dbo.StatMain.SMLocation, dbo.StatMain.SMDate, dbo.StatMain.SMTherapist, dbo.DepartmentCodes.DeptDesc, dbo.TherapistCodes.TDesc FROM dbo.StatMain LEFT OUTER JOIN dbo.DepartmentCodes ON dbo.StatMain.SMLocation = dbo.DepartmentCodes.DeptIndex LEFT OUTER JOIN dbo.TherapistCodes ON dbo.StatMain.SMTherapist = dbo.TherapistCodes.TIndex WHERE (dbo.StatMain.SMLocation = @smlocation) AND (dbo.StatMain.SMTherapist = @smtherapist) AND (dbo.StatMain.SMDate > @smdate)My problem is I want to pass a wildcard to @smlocation and/or @smtherapist. I cannot find a wildcard character for an integer field. # will replace one digit, but if I am searching a field that is 6 digits long I would have to search for #, then ##, then ###, etc. I am retrieving the paramaters (@smlocation, @smtherapist, @smdate) from drop down boxes that include specific codes, or all. I am not an expert in SQL and have searched everywhere but can only find information on searching for characters, not integers. I need a wildcard character that will include all numbers at one time. Can you help me?" |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2005-04-13 : 10:38:37
|
| WHERE (dbo.StatMain.SMLocation like case @smlocation when '' then '%' else @smlocation end) when your @smlocation is empty (or you can change it to null), search with the percent (%), which is a wildcard. Otherwise, search for what was entered. Or you can simply do this:WHERE (dbo.StatMain.SMLocation like '%' + @smlocation + '%') but that will preclude SQL SERVER from using an index (if one is available for that column). |
 |
|
|
|
|
|
|
|