Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Hoe to put If Else condition to check one coulmn value is present in another set of column values in sql 2008

$
0
0

Hi All,

I have main data set which consists of lacks of records and below is my query

DECLARE @USER_DT DATETIME SET @USER_DT = '2013-08-01' DECLARE @RANGE_DATE DATETIME SELECT distinct @RANGE_DATE = RANGE_DATE FROM dbo.TABLE WHERE RANGE_DATE >= (CONVERT(VARCHAR(8), DATEADD (M, -2, GETDATE()), 21)+ '26') AND RANGE_DATE <= (CONVERT(VARCHAR(8), DATEADD (M, -1, GETDATE()), 21)+ '25') IF(@USER_DT = @RANGE_DATE ) BEGIN SELECT * FROM MAIN_TABLE WHERE USER_DATE = @USER_DT AND RANGE_DATE >= (CONVERT(VARCHAR(8), DATEADD (M, -2, GETDATE()), 21)+ '26') AND RANGE_DATE <= (CONVERT(VARCHAR(8), DATEADD (M, -1, GETDATE()), 21)+ '25') END BEGIN SELECT * FROM MAIN_TABLE WHERE USER_DATE = @USER_DT AND RANGE_DATE >= (CONVERT(VARCHAR(8), DATEADD (M, -1, GETDATE()), 21)+ '26') AND RANGE_DATE <= (CONVERT(VARCHAR(8), DATEADD (M, 0, GETDATE()), 21)+ '25') END

i.e. @USER_DT is for user selection in SSRS Report window. Now, let say he has enter '2013-08-01' now second parameter @RANGE_DT is created for storing distinct dates values now my problem is I  want to check that user entered date in @Range_DT and if it is present as shown in the above query i will get desired output. But thing is we can check only single value in If-Else and I wanna check single date value is present or not and displya output accordingly. Is there any way to do this (This later i am going to put in SSRS report).

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>