September 16, 2010 at 12:15 pm
I have multi selection boxes in my search page that a person can select some or not when submitting a search. It works if everybox is selected and a value passed in the parameter but wanted to see how I could resolve the parameter if that value is not filled. I am trying the included code in my where clause but can't seem to make it work either. @pm is passed as '' which I don't want but rather not include @pm in the where if its got nothing passed to it. Make sense????
AND
Len(IsNull(@PM,'')) = 0
OR
CHARINDEX( '~' + PM1.PM70.Projects.Project_Manager + '~', @pm) > 0
September 16, 2010 at 12:25 pm
Richard Holloway
It does help if you post your forum question including table definition(s),
some sample data, and your complete procedure. Follow the first link in my signature block to learn how you can do this quickly and easily.
With that information I am sure some one will give you a tested answer to your question.
September 16, 2010 at 12:28 pm
What's the environement? SSRS or "normal" application?
September 16, 2010 at 12:36 pm
Richard Holloway (9/16/2010)
Normal environment. The @pm is a nvarchar(I set to 4000) just in case a person selected quite a few from the listbox. I can post the whole sp if needed and my test params I am using.
And you table definitions, sample data and desired results
September 16, 2010 at 1:49 pm
I think I got it figured out. Kind of using DUAL in Oracle. I found this thread while searching some more after posting. http://www.sqlservercentral.com/Forums/Topic776445-9-1.aspx and utilized the statement
AND PM1.PM70.Company_List.Company_Name = (case when @Company is null then PM1.PM70.Company_List.Company_Name else @Company end)
September 16, 2010 at 11:03 pm
Actually your original approach was more efficient:
AND (@Company is null OR PM1.PM70.Company_List.Company_Name = @Company)
_____________
Code for TallyGenerator
September 17, 2010 at 9:42 am
If the parameters are optional... dynamic SQL is your best bet.
http://www.sommarskog.se/dyn-search-2005.html
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
I've done this with SQL 2000, of course it's much easier with SQL2005+ because you can using nvarchar(max) to hold the query, but you can write some pretty complicated stuff with nvarchar(4000).
September 17, 2010 at 10:25 am
Cool will look into that. I am using 2005.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply