January 11, 2010 at 8:27 am
yes I could restrict it by entering any or all parameters
January 11, 2010 at 8:44 am
i mean i could restrict it by @param.
Could you think of SQL construct. How should be query be ?
Thnaks for your help
January 11, 2010 at 8:47 am
Try this:
-- parameters
DECLARE @Year CHAR(4), @Month VARCHAR(10)
SELECT @Year = '2008', @Month = 'February'
-- variable
DECLARE @RowsToReturn INT
-- test rowcount using user-supplied values; ignore parameter if NULL
SELECT @RowsToReturn = COUNT(*)
FROM #test t
WHERE t.[year] = ISNULL(@Year, t.[year])
AND t.[month] = ISNULL(@Month, t.[month])
IF @RowsToReturn = 0
SELECT *
FROM #test t
ELSE
SELECT *
FROM #test t
WHERE t.[year] = ISNULL(@Year, t.[year])
AND t.[month] = ISNULL(@Month, t.[month])
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 11, 2010 at 9:11 am
Great !!! Its working
Thanks for your help.
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply