Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bhushan_juare
Starting Member
45 Posts |
Posted - 2013-08-31 : 01:39:48
|
Hi All,I have main data set which consists of lacks of records and below is my queryDECLARE @USER_DT DATETIME SET @USER_DT = '2013-08-01'DECLARE @RANGE_DATE DATETIMESELECT distinct @RANGE_DATE = RANGE_DATE FROMdbo.TABLE WHERERANGE_DATE >= (CONVERT(VARCHAR(8), DATEADD (M, -2, GETDATE()), 21)+ '26')ANDRANGE_DATE <= (CONVERT(VARCHAR(8), DATEADD (M, -1, GETDATE()), 21)+ '25')IF(@USER_DT = @RANGE_DATE ) BEGINSELECT * FROM MAIN_TABLEWHERE USER_DATE = @USER_DTANDRANGE_DATE >= (CONVERT(VARCHAR(8), DATEADD (M, -2, GETDATE()), 21)+ '26') ANDRANGE_DATE <= (CONVERT(VARCHAR(8), DATEADD (M, -1, GETDATE()), 21)+ '25')ENDBEGINSELECT * FROM MAIN_TABLEWHERE USER_DATE = @USER_DTANDRANGE_DATE >= (CONVERT(VARCHAR(8), DATEADD (M, -1, GETDATE()), 21)+ '26') ANDRANGE_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). |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-08-31 : 04:55:01
|
no need of variable in that case. just use a IF EXISTS check likeIF EXISTS (SELECT 1 FROMdbo.TABLE WHERERANGE_DATE >= (CONVERT(VARCHAR(8), DATEADD (M, -2, GETDATE()), 21)+ '26')ANDRANGE_DATE <= (CONVERT(VARCHAR(8), DATEADD (M, -1, GETDATE()), 21)+ '25')AND RANGE_DATE = @USER_DT)...ELSE..END ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|