SELECT u.uID as 'รหัส',u.tDate as 'วันที่'
,case when u.Start Between ''06:00:00'' and '12:00:00' Then '06:00-12:00'
when u.End Between '12:00:01' and '18:00:00' Then '12:00-18:00'
when u.Start Between '06:00:00' and '13:30:00' Then ''06:00-12:00'
when u.End Between '12:00:01' and '18:00:00' Then '12:00-18:00'
else '' end as 'เวลาเปิด-ปิด'
,SUM(u.Money) as 'เงินรวมทั้งหมด'
From table_use u
WHERE CONVERT(nvarchar(10),u.tDate,126)='2012-01-10'
Group by u.uID,u.tDate,u.Start,u.End
SELECT u.uID as 'รหัส',u.tDate as 'วันที่'
,case when u.Start Between ''06:00:00'' and '12:00:00' Then '06:00-12:00'
when u.End Between '12:00:01' and '18:00:00' Then '12:00-18:00'
when u.Start Between '06:00:00' and '13:30:00' Then ''06:00-12:00'
when u.End Between '12:00:01' and '18:00:00' Then '12:00-18:00'
else '' end as 'เวลาเปิด-ปิด'
,SUM(u.Money) as 'เงินรวมทั้งหมด'
From table_use u
WHERE CONVERT(nvarchar(10),u.tDate,126)='2012-01-10'
Group by u.uID,u.tDate, (case when u.Start Between ''06:00:00'' and '12:00:00' Then '06:00-12:00'
when u.End Between '12:00:01' and '18:00:00' Then '12:00-18:00'
when u.Start Between '06:00:00' and '13:30:00' Then ''06:00-12:00'
when u.End Between '12:00:01' and '18:00:00' Then '12:00-18:00'
else '' end)