on 11-20-2017 7:29 AM
DECLARE @StartDate datetime='2017-11-01'
DECLARE @EndDate datetime=SYSDATETIME()
;WITHdaysAS
(
SELECTDATEADD(DAY, n,DATEADD(DAY,DATEDIFF(DAY, 0, @StartDate), 0))as d
FROM (SELECTTOP (DATEDIFF(DAY, @StartDate, @EndDate)+ 1)
n =ROW_NUMBER()OVER (ORDERBY [object_id])- 1
FROMsys.all_objectsORDERBY [object_id] )AS n
)
selectdays.d,count(t.EXPECTEDDATE)
FROMdaysLEFTOUTERJOIN DEPOSIT as t
ON t.EXPECTEDDATE >=days.d AND t.EXPECTEDDATE <DATEADD(DAY, 1,days.d)
GROUPBYdays.d
ORDERBYdays.d;
Hi Jaya,
You can't use Declare or With, in a Derived table in Universe. Try to define n and days as tables in the inner queries, something like this.
select days.d, count(t.EXPECTEDDATE)
FROM
--next 12 lines (include table n) is the SQL for table days
(
SELECT DATEADD (DAY, n.rn, DATEADD(DAY,DATEDIFF(DAY, 0, CONVERT(datetime, '2017-11-01')), 0)) as 'd'
FROM
--next 5 lines (Italicized) is the SQL for table n
(
SELECT TOP (DATEDIFF(DAY, CONVERT(datetime, '2017-11-01'), Sysdatetime())+ 1), ROW_NUMBER() OVER (ORDERBY [object_id]) - 1 as 'rn'
FROM sys.all_objects ORDER BY [object_id]
) n
) days LEFT OUTER JOIN DEPOSIT t
ON (t.EXPECTEDDATE >= days.d AND t.EXPECTEDDATE < DATEADD(DAY, 1,days.d)) --(in this line we're joining tables days and t)
GROUP BY days.d
ORDER BY days.d;
Try that and let us know if that works.
Thanks,
Mahboob Mohammed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.