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 |
|
fralo
Posting Yak Master
161 Posts |
Posted - 2008-04-30 : 09:22:12
|
| I create a stored procedure like such:"create procedure tmptable_query (@lname varchar(20)) as select * from #temp_table where lname like ISNULL(@lname+'%',lname)"Unfortunately, it only returns exact matches, as if it were written as "where lname = ISNULL(@lname, lname)"However, if I query from a static table the code works correctly.Any ideas on what could be wrong?Thank you. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-30 : 09:29:51
|
| Works for me!Are you sure there is matching data populated in #temp_table?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-30 : 09:31:15
|
[code]-- Prepare sample dataDECLARE @Sample TABLE (Data VARCHAR(20))INSERT @SampleSELECT 'Peso' UNION ALLSELECT 'Yak' UNION ALLSELECT 'SQLTeam'-- Prepare searchDECLARE @Search VARCHAR(20)-- Search when NULLSELECT *FROM @SampleWHERE Data LIKE ISNULL(@Search + '%', Data)-- Search when data existsSET @Search = 'SQL'SELECT *FROM @SampleWHERE Data LIKE ISNULL(@Search + '%', Data)-- SimplerSELECT *FROM @SampleWHERE Data LIKE ISNULL(@Search, '') + '%'[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
fralo
Posting Yak Master
161 Posts |
Posted - 2008-04-30 : 09:45:08
|
| Yes, there is definitely data in my temp table. If I pass in a parameter like 'Smith', it will work correctly. One thing I should mention, however, is that I am running this from a .NET application. There may be factors specific to that which are causing these problems. But if I run this straight from within sql server, it works fine. I probably should have pointed that out to begin with. |
 |
|
|
|
|
|
|
|