Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcards on int cols 1

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
I seem to have come across this before, but can't remember what I did as a solution. It is a prtty simple problem, I think.

Is there a way to use wildcards on a int column? I have a sp where the variable for the filter on the int column may or may not have value.

WHERE intcol = @intvar

@intvar might be "%" or it might be a valid int value.

The quickest workaround I can think of is

WHERE cast(intcol, varchar(50)) LIKE @intvar

Basically, if there is no value for @intval, I want to return all records

 
Without casting, try passing a NULL instead of a % for a selection of all values. Then, your WHERE becomes:

WHERE (intcol = @intvar OR @intvar IS NULL)
 
Greetings from another vancouverite.

Cool. Thanks. Seems to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top