thomas-sherrouse
asked on
Expression to Find Previous Sunday - SQL Server 2008 R2 Report Builder
I've looked around and can't quite find what I need in terms of an expression that will display the Previous Sunday's Date in a Report on SQL Server 2008 R2 Reporting Services Report.
I've got:
= dateadd(dd,(datediff(dd,-5 3684,a.DAT E)/7)*7,-5 3684)
and it's giving me the error of "dd" isn't declared and "a" isn't declared. Instead of troubleshooting and wasting time I decided to ask the Experts here. Could someone help me out with this.
Thanks
I've got:
= dateadd(dd,(datediff(dd,-5
and it's giving me the error of "dd" isn't declared and "a" isn't declared. Instead of troubleshooting and wasting time I decided to ask the Experts here. Could someone help me out with this.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For an equivalent SSRS expression compared to what you've got, try this:
=DateAdd("d", CLng(DateDiff("d", "1753-01-07", Fields!TheDate.Value)/7)*7 , "1753-01-07")
Some explanation:
o the number -53684 converts to a particular Sunday far away in the year 1753. To avoid implicit conversion (which works differently in SSRS), I've pre-translated it in the expression.
o the division by 7 will keep the decimals as well, unlike in SQL. To remove them I've added a CLng conversion.
o "d" in SSRS is the equivalent of dd in the SQL statement, note especially the double quotes.
o Fields!TheDate.Value refers to a dataset field called TheDate and should contain a datetime (or date)
=DateAdd("d", CLng(DateDiff("d", "1753-01-07", Fields!TheDate.Value)/7)*7
Some explanation:
o the number -53684 converts to a particular Sunday far away in the year 1753. To avoid implicit conversion (which works differently in SSRS), I've pre-translated it in the expression.
o the division by 7 will keep the decimals as well, unlike in SQL. To remove them I've added a CLng conversion.
o "d" in SSRS is the equivalent of dd in the SQL statement, note especially the double quotes.
o Fields!TheDate.Value refers to a dataset field called TheDate and should contain a datetime (or date)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great Thanks! - Both of these worked
SELECT dateadd(dd,(datediff(dd,-5
perhaps the error you are seeing is with some other part of the query?