MSSQL Parameters
When I was working on a quick store procedure with optional parameters and preferred not to have to write dozens of if's in TSQL I came upon this page that made my life a little easier (a fairly simple trick, but I thought I'd share):
Excerpt:
ALTER PROCEDURE dbo.YourProcedureName
@value1 CHAR(100) = NULL,
@value2 CHAR(100) = NULL,
@value3 CHAR(100) = NULL,
@value4 CHAR(100) = NULL
AS
SELECT
column1,
column2,
column3,
column4
FROM
Table_Name
WHERE
((@value1 IS NULL) OR (column1 = @value1))
AND ((@value2 IS NULL) OR (column2 = @value2))
AND ((@value3 IS NULL) OR (column3 = @value3))
AND ((@value4 IS NULL) OR (column4 = @value4))

80 Comments:
wxYOZf Very good blog! Thanks!
EOimmh Magnific!
Nice Article.
Please write anything else!
Thanks to author.
Magnific!
Magnific!
Thanks to author.
Hello all!
Good job!
WmCAOx write more, thanks.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Good job!
Good job!
Hello all!
Magnific!
Wonderful blog.
Please write anything else!
Please write anything else!
Hello all!
Nice Article.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Good job!
Hello all!
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Oops. My brain just hit a bad sector.
Friends help you move. Real friends help you move bodies
Build a watch in 179 easy steps - by C. Forsberg.
When there's a will, I want to be in it.
Hello all!
Build a watch in 179 easy steps - by C. Forsberg.
Give me ambiguity or give me something else.
Good job!
A lot of people mistake a short memory for a clear conscience.
What is a free gift ? Aren't all gifts free?
The gene pool could use a little chlorine.
What is a free gift ? Aren't all gifts free?
Suicidal twin kills sister by mistake!
When there's a will, I want to be in it.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Thanks to author.
Magnific!
A lot of people mistake a short memory for a clear conscience.
Friends help you move. Real friends help you move bodies.
When there's a will, I want to be in it.
Friends help you move. Real friends help you move bodies.
The gene pool could use a little chlorine.
When there's a will, I want to be in it.
Calvin, we will not have an anatomically correct snowman!
Clap on! , Clap off! clap@#&$NO CARRIER
Good job!
Lottery: A tax on people who are bad at math.
Please write anything else!
Wonderful blog.
A lot of people mistake a short memory for a clear conscience.
Ever notice how fast Windows runs? Neither did I.
The gene pool could use a little chlorine.
What is a free gift ? Aren't all gifts free?
Suicidal twin kills sister by mistake!
Lottery: A tax on people who are bad at math.
Nice Article.
Lottery: A tax on people who are bad at math.
Magnific!
Friends help you move. Real friends help you move bodies.
Hello all!
What is a free gift ? Aren't all gifts free?
I'm not a complete idiot, some parts are missing!
When there's a will, I want to be in it.
Save the whales, collect the whole set
All generalizations are false, including this one.
Wonderful blog.
Suicidal twin kills sister by mistake!
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Save the whales, collect the whole set
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
A lot of people mistake a short memory for a clear conscience.
I'm not a complete idiot, some parts are missing!
miley cyrus nude miley cyrus nude miley cyrus nude
ups sorry delete plz [url=http://duhum.com].[/url]
http://markonzo.edu qcncr pinochet http://blog.tellurideskiresort.com/members/paxil-side-effects.aspx http://clarinex.indieword.com/ nocomments cussing http://www.ecometro.com/Community/members/celebrex-side-effects.aspx http://profiles.friendster.com/levaquin#moreabout placeparents enforcememt http://www.netknowledgenow.com/members/ativan-side-effects.aspx http://blog.bakililar.az/famciclovir/ http://profiles.friendster.com/lexapro#moreabout chassis taboo http://blog.tellurideskiresort.com/members/buy-clomid.aspx
Post a Comment
Links to this post:
Create a Link
<< Home