sql server - Using a SQL query, how can I select every date within a range? -
i'm querying support ticket database, , each ticket has column "date opened" , "date closed." tickets remain open multiple days, need able pull number of tickets open on each day.
example, 4/8/14, need know how many tickets opened on 4/8, combined total number of unclosed tickets opened prior 4/8 remained still open @ 12:00am on 4/8 (may or may not have been closed during or after 4/8).
this seems straightforward enough single date, need write query pull complete range of dates.
example, need write query returns every date between 1/1/14 , 4/10/14 along total number of tickets open on each date (including dates on 0 tickets open).
is possible using queries or subqueries, without using stored procedures or temporary datatables?
we're pulling data excel , calculating date stats there, excel not scalable solution , we'd have sql perform work can migrate report ssrs (sql server reporting services) down road.
your question not clear me, sqlserver 2005 or better (sqlserver 2008 or better type date) can create calendar. 1 way it
with [counter](n) (select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1 union select 1) , days(n) (select row_number() on (order (select null)) [counter]) , months (n) (select n - 1 days n < 13) select distinct cast(dateadd(day, days.n, dateadd(month, months.n, '20131231') ) date) months cross join days order 1
if need more year add new cte accordingly
Comments
Post a Comment