Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Union order
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01343299
Message ID:
01343305
Views:
21
>I've got a select statement that I'm unioning and my results come back with the second select statements data in the first row and the first selects data in the second row.
>
>Here's the statement:
>SET @cJobNo = '11708'
>
>SELECT TimeHD.Empid, TimeHD.EmpName,
>	sum(regtime) as RegTime,sum(overtime) as OverTime, Sum(doubletime) as DoubleTime,
>	sum(regtime+overtime+doubletime) as TotalHours1
>FROM TimeHd INNER JOIN
>	TimeItms ON TimeHd.timecrdno = TimeItms.timecrdno
>Where TimeItms.JobNo = @cJobNo and
>	TimeItms.[distributed] <> 1
>
>group by TimeHD.Empid, TimeHD.EmpName
>
>UNION ALL
>
>SELECT TimeHD.Empid, TimeHD.EmpName,
>	sum(regtime) as RegTime,sum(overtime) as OverTime, Sum(doubletime) as DoubleTime,
>	sum(regtime+overtime+doubletime) as TotalHours1
>FROM TimeHd INNER JOIN
>	TimeItms ON TimeHd.timecrdno = TimeItms.timecrdno
>Where TimeItms.JobNo = @cJobNo and
>	TimeItms.[distributed] = 1
>
>group by TimeHD.Empid, TimeHD.EmpName
>
>order by empid
>I've tried switching the where clauses around but it doesn't seem to matter. Any ideas?


It should be sorted by EmpID. Do you have two records with the same ID? If yes, create a SortOrder field to sort the way you want explicitly.

BTW, funny, it's 2 seconds difference between my answer and Sergey's.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform