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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcard for int in stored procedure

Status
Not open for further replies.

katz

Technical User
Oct 20, 2000
2
GB
hi,
newbie here.

Within a stored procedure is there any way to use a wildcard to compare a integer input parameter to a data type int field in the tables?
extract:

@DriverID int
WHERE
(DRIVER_ID =
CASE WHEN (@DriverID IS NULL) THEN '%'
WHEN (@DriverID NOT LIKE ' ') THEN '%'
ELSE (@DriverID)
END)

Thanx
[sig][/sig]
 
Instead, I would simplify the problem as in:

IF @driver_id IS NULL
BEGIN
SELECT *
FROM TABLE
END
ELSE
BEGIN
SELECT *
FROM TABLE
WHERE driver_id = @driver_id
END

This will produce much more efficient code than using wildcards.

Tom [sig][/sig]
 
HI,
THANKS FOR THAT, BUT WOULD THIS WORK IF THERE ARE MULTIPLE CLAUSES? [sig][/sig]
 
katz,
I would suggest to use CONVERT(VARCHAR(4),@DriverID) and assign it to another varchar(4) variable, in that way you could use nulls and/or wildcards.

Just a thought.

J.C.
[sig][/sig]
 
Or you could use EXECUTE to build the select statement once, dynamically. I would either simplify the code, or use EXECUTE... depending on your needs. Eliminating the wildcard, if you can, is always better (as J.C. suggested).

Tom [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top