- Moderator
- #1
I just learned this, and thought I'd share.
In a stored procedure, you can pass an optional value like this:
This way, if @Optional isn't passed, then all records are selected, but if @Optional IS passed, then it filters accordingly.
I thought it was spiffy, so I thought I'd share.
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg
In a stored procedure, you can pass an optional value like this:
Code:
CREATE PROC MyProc
@Optional int = NULL
AS
BEGIN
SELECT somerows FROM sometable
WHERE
((@Optional IS NULL) OR (selctionfield = @Optional))
END
This way, if @Optional isn't passed, then all records are selected, but if @Optional IS passed, then it filters accordingly.
I thought it was spiffy, so I thought I'd share.
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg