这是我的查询
select
dtfromdate, dttodate,
(SELECT DATEDIFF(day, dtfromdate, dtTodate)) AS NumberOfDays,
fltspl
from dbo.tblHR_SpecialLeaveTransaction
where
nvrempcode = 'MCL1218' and nvrstatus = 1
order by
dtfromdate
结果 :
dtfromdate dttodate NumberOfDays fltspl
----------------------- ----------------------- ------------ ----------------------
2012-05-01 00:00:00 2012-05-31 00:00:00 30 30
另一个查询
select
dtfromdate, dtTodate,
(SELECT DATEDIFF(day, dtfromdate, dtTodate) ) AS NumberOfDays,
fltcl, fltsl, fltpl, fltcompoff, fltod, fltlop,
isnull(fltflexiL, 0) as fltflexiL
from
tblhr_leavetransaction
where
nvrempcode = 'MCL1218' and nvrstatus = 1
order by
dtfromdate
结果:
dtfromdate dtTodate NumberOfDays fltcl fltsl fltpl fltcompoff fltod fltlop fltflexiL
----------------------- ----------------------- ------------ ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ----------------------
2011-01-14 00:00:00 2011-01-14 00:00:00 0 1 0 0 0 0 0 0
2011-01-17 00:00:00 2011-01-17 00:00:00 0 1 0 0 0 0 0 0
2011-01-25 00:00:00 2011-01-25 00:00:00 0 0 0 0 0 1 0 0
2011-04-01 00:00:00 2011-04-02 00:00:00 1 0 0 0 0 2 0 0
2011-05-14 00:00:00 2011-05-14 00:00:00 0 0 0 0 0 1 0 0
2011-05-16 00:00:00 2011-05-16 00:00:00 0 0 0 0 1 0 0 0
2011-05-18 00:00:00 2011-05-18 00:00:00 0 1 0 0 0 0 0 0
2011-05-19 00:00:00 2011-05-20 00:00:00 1 0 2 0 0 0 0 0
2011-05-21 00:00:00 2011-05-21 00:00:00 0 1 0 0 0 0 0 0
2011-05-23 00:00:00 2011-05-23 00:00:00 0 0 0 0 1 0 0 0
我需要这样的输出,
dtfromdate dtTodate NumberOfDays fltcl fltsl fltpl fltcompoff fltod fltlop fltflexiL fltspl
----------------------- ----------------------- ------------ ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ----------
2011-01-14 00:00:00 2011-01-14 00:00:00 0 1 0 0 0 0 0 0 0
2011-01-17 00:00:00 2011-01-17 00:00:00 0 1 0 0 0 0 0 0 0
2011-01-25 00:00:00 2011-01-25 00:00:00 0 0 0 0 0 1 0 0 0
2011-04-01 00:00:00 2011-04-02 00:00:00 1 0 0 0 0 2 0 0 0
2011-05-14 00:00:00 2011-05-14 00:00:00 0 0 0 0 0 1 0 0 0
2011-05-16 00:00:00 2011-05-16 00:00:00 0 0 0 0 1 0 0 0 0
2011-05-18 00:00:00 2011-05-18 00:00:00 0 1 0 0 0 0 0 0 0
2011-05-19 00:00:00 2011-05-20 00:00:00 1 0 2 0 0 0 0 0 0
2011-05-21 00:00:00 2011-05-21 00:00:00 0 1 0 0 0 0 0 0 0
2011-05-23 00:00:00 2011-05-23 00:00:00 0 0 0 0 1 0 0 0 0
2012-05-01 00:00:00 2012-05-31 00:00:00 30 0 0 0 0 0 0 0 30