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
 SPROC PARAMETERS

Author  Topic 

Shrews14
Starting Member

37 Posts

Posted - 2008-05-20 : 10:54:59
Hi ALL,

wondering if anybody can help me, i've writen a stored procedure to query my database, i want to be able to added a wildcard into a parameter incase i don't want to use it.

(don't laugh at my efforts!!!!:))
i've tried

IF @<PARAM> = NULL
@<PARAM> = LIKE %

I sure this is a simple thing to add basically i need to replace a null with everything!!

can anybody help?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-20 : 11:04:19
Why should you add a wildcard .i think u can use like this

(field=@PARAM OR @PARAM IS NULL)
Go to Top of Page

Shrews14
Starting Member

37 Posts

Posted - 2008-05-20 : 11:41:44
Thanks visakh16, works like a dream

i was using a wildcard because my skills are still raw and i was trying to use these skills with my logic. Not sure why what your writen works but sounds like it means.

where <field> = <something> or <Field not in where clause>
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-20 : 11:44:44
quote:
Originally posted by Shrews14

Thanks visakh16, works like a dream

i was using a wildcard because my skills are still raw and i was trying to use these skills with my logic. Not sure why what your writen works but sounds like it means.

where <field> = <something> or <Field not in where clause>


Exactly. It considers this filtering condition only when you have a non NULL value passed to your parameter. In cases where its NULL, it just bypasses this filter because of OR
Go to Top of Page
   

- Advertisement -