BeachSandGuy
Programmer
Hi, I am having a problem with a Reporting Services SQL statement.
1st. Have table like the following (omitted non-essentials):
Record# - Skill# - StartDate - EndDate
1 - 100 - 1/1/1980 - 12/31/2008
2 - 100 - 1/1/2009 - NULL
3 - 200 - 1/1/2009 - NULL
Essentially if the record is "active", end date is null.
In reporting services, I want to use a report parameter to limit the return of records to those with NULLs, the active records. So the parameter @ExcludeTermedRecords, boolean data type, I have default set to True.
the SQL is:
Select * from dbo.table
Where StartDate >=@StartDate AND
(@EndDate is null or EndDate <=@EndDate) AND
(If @ExcludeTermedRecords = True
Begin
Endate is Null
End)
I get an error message, "Incorrect syntax near the keyword 'if'. Incorrect syntax near 'EndDate'. (Microsoft SQL Server, Error: 156)
I've tried case statements too, I am stumped. Anyone have any ideas. Surely I'm not the first person to try to conditionally route with IF statements. I've searched high and low and couldn't find an answer. Thanks in advance!
Ian
1st. Have table like the following (omitted non-essentials):
Record# - Skill# - StartDate - EndDate
1 - 100 - 1/1/1980 - 12/31/2008
2 - 100 - 1/1/2009 - NULL
3 - 200 - 1/1/2009 - NULL
Essentially if the record is "active", end date is null.
In reporting services, I want to use a report parameter to limit the return of records to those with NULLs, the active records. So the parameter @ExcludeTermedRecords, boolean data type, I have default set to True.
the SQL is:
Select * from dbo.table
Where StartDate >=@StartDate AND
(@EndDate is null or EndDate <=@EndDate) AND
(If @ExcludeTermedRecords = True
Begin
Endate is Null
End)
I get an error message, "Incorrect syntax near the keyword 'if'. Incorrect syntax near 'EndDate'. (Microsoft SQL Server, Error: 156)
I've tried case statements too, I am stumped. Anyone have any ideas. Surely I'm not the first person to try to conditionally route with IF statements. I've searched high and low and couldn't find an answer. Thanks in advance!
Ian