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 |
CSharpNewbie
Starting Member
39 Posts |
Posted - 2010-06-28 : 14:54:55
|
Hi, I am creating a sql stored proc for a search function. I am having problems with the query, given the possibilities of null or empty stringsI would greatly appreciate if someone can help with the query:Select RecID, VendorNum, VendorName, InvoiceNum, ItemNum, (SELECT CONVERT(VARCHAR(11), DateOfRecord, 106) AS [DD MON YYYY]) As DateOfRecord, NeedsUpdate, RecAddUserID From tbInvoiceLogWHEREIf @ItemNum is Not Null, then(CASE @SearchFilterWHEN 0 THEN @ItemNum + '%'WHEN 1 THEN '%' + @ItemNum + '%'WHEN 2 THEN '%' + @ItemNumEND)AND if @VendorNum is Not Null, then VendorNum = @VendorNumAND if @RecSearchUserID i Not Nulll, then RecSearcherID = @RecSearchIDAND DateOfRecord BETWEEN @StartDate AND @EndDate |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-06-28 : 15:56:51
|
Where's the equality?What do you want to make @ItemNum equal to?Let's say Col1WHERE Col1 LIKE CASE WHEN @SearchFilter = 0 THEN @ItemNum + '%' WHEN @SearchFilter = 0 THEN '%' + @ItemNum + '%' WHEN @SearchFilter = 0 THEN '%' + @ItemNum-- ELSE @ItemNum END AND VendorNum = COALESCE(@VendorNum, VendorNum) AND RecSearcherID = COALESCE(@RecSearchUserID, RecSearcherID) AND DateOfRecord BETWEEN @StartDate AND @EndDate Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
CSharpNewbie
Starting Member
39 Posts |
Posted - 2010-06-29 : 07:35:29
|
Brett, this is in a where clauseItemNUm = @ItemNum, depending on the value of the SearchFilter |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|