Author |
Topic |
xholax
Starting Member
12 Posts |
Posted - 2010-10-20 : 14:45:13
|
Hello, I hope you can help me , Im new at building querys and Transact SQL and I need one query for my job. As you can see in the picture above, I have the table (that is a result from another query, that recieve 2 paramares @startdate, @enddate), so I need a summary from there , omiting some restrictions as you can see in teh picture, please I hope you can help me and sorry for my bad english. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-20 : 15:35:02
|
[code]-- a table variable for test datadeclare @Sample table ([date] datetime, shift varchar(10), fruit varchar(10), times int)-- inserting the test datainsert @Sampleselect '20101001','Dia','Apple',2 union allselect '20101001','Noche','Apple',3 union allselect '20101002','Dia','Apple',4 union allselect '20101002','Noche','Apple',5 union allselect '20101003','Dia','Apple',9 union allselect '20101003','Noche','Apple',9 union allselect '20101004','Noche','Apple',7 union allselect '20101005','Dia','Apple',8 union allselect '20101005','Noche','Apple',5select dia.[date],dia.fruit,dia.times+noche.times as [sum times]from @Sample as diajoin @Sample as nocheon noche.[date] = dateadd(dd,-1,dia.[date])and noche.shift='Noche'where dia.shift='Dia'-- date fruit sum times-- ----------------------- ---------- ------------- 2010-10-02 00:00:00.000 Apple 7-- 2010-10-03 00:00:00.000 Apple 14-- 2010-10-05 00:00:00.000 Apple 15[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
xholax
Starting Member
12 Posts |
Posted - 2010-10-20 : 20:05:19
|
Thanks, I really appreciate your help . |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-21 : 02:21:06
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|