sql - View as table with range od date for each record -


i have table employees columns surname, names, birth date etc. want have table each row in employees table have range of dates, example:

surname0 , day()+0 surname0 , day()+1  surname0 , day()+2  .................  surname0 , day()+30  surname1 , day()+0  surname1 , day()+1  surname1 , day()+2 .................  surname1 , day()+30 ................. ................. surname100 , day()+0  surname100 , day()+1  surname100 , day()+2 .................  surname100 , day()+30 

i have no idea how that.

the main idea have list of employees , number of activities per day. in case particular employee has no task specific day have "0". have table tasks, columns teams (consist of several surnames separated commas), day, task, description etc. comparing table 1 mentioned @ beginning range of dates per each surname, number of task/activities per day per surname. on other way using smth this

select distinct surname, day, count(surname) on (partition day, surname) employees left outer join tasks on team '%'+surname+'%'

i dont rows "0" 0 values employees have no tasks particular day, reason why want have table range of days , combining table tasks table can list of employees following 30 days , number of tasks.

i work on ms sql 2005 server

thanks!

maybe can use cte (common table expression):

;with days (   select convert(datetime,convert(varchar(10), getdate(), 120)+' 00:00:00') day   union   select d.day+1   days d   datediff(day,convert(datetime,convert(varchar(10), getdate(), 120)+' 00:00:00'), d.day+1)<=30 ) select * days d   join employees e on 1=1 

more info cte: https://msdn.microsoft.com/en-us/library/ms175972(v=sql.90).aspx


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -