Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help sorting the following Select Query

Author  Topic 

eljapo4
Posting Yak Master

100 Posts

Posted - 2012-05-03 : 06:58:04
Hi I have 3 separate views that I am combining together in this statement:
SELECT [ID]        --selects job data per employee
,[TimeSheetDate]
,[WorkstudyCode]
,[Employee_Name]
,[TimeOn]
,[TimeOff]
,[Job_Analysis_Group_Name]
,[Qty]
,[SAMS]
,[Personal_Needs]
,[SAM Recovery & Personal Needs TOTAL]
,[Changeover]
,[Downtime]
,[Maintenance]
,[Meetings]
,[Personal + Downtime Recovery TOTAL]
,[Pack]
,[Line_Lead]
,[Team_Leader]
,[ALL TOTALS]
FROM [LIPS_Norway].[dbo].[vw_Employee_Timesheet_Results]

UNION

SELECT [ID] --summarises job data per employee
,'' AS [TimeSheetDate]
,'' AS [WorkstudyCode]
,[Employee_Name]
,'' AS [TimeOn]
,'' AS [TimeOff]
,'' AS [Job_Analysis_Group_Name]
,'' AS [Qty]
,[SAMS]
,[Personal_Needs]
,[SAM Recovery & Personal Needs TOTAL]
,[Changeover]
,[Downtime]
,[Maintenance]
,[Meetings]
,[Personal + Downtime Recovery TOTAL]
,[Pack]
,[Line_Lead]
,[Team_Leader]
,[ALL TOTALS]
FROM [LIPS_Norway].[dbo].[vw_Employee_Timesheet_Results_Summary]

UNION

SELECT [ID] --Summarises the job data per employee summary
,'' AS [TimeSheetDate]
,'' AS [WorkstudyCode]
,'' AS [Employee_Name]
,'' AS [TimeOn]
,'' AS [TimeOff]
,'' AS [Job_Analysis_Group_Name]
,'' AS [Qty]
,[SAMS]
,[Personal_Needs]
,[SAM Recovery & Personal Needs TOTAL]
,[Changeover]
,[Downtime]
,[Maintenance]
,[Meetings]
,[Personal + Downtime Recovery TOTAL]
,[Pack]
,[Line_Lead]
,[Team_Leader]
,[ALL TOTALS]
FROM [LIPS_Norway].[dbo].[vw_Employee_Timesheet_Summary]

ORDER BY Employee_Name, [WorkstudyCode], TimeOn, ID


In my output window I have my Overall Summary, followed by Employee Summary and then Job Summary. The way i'd like to see this is for example if I have 3 employees:
Job Summary
Employee Summary
Job Summary
Employee Summary
Job Summary
Employee Summary
Overall Summary

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2012-05-03 : 07:22:44
Can you please provide sample data and desired output ..
Go to Top of Page

eljapo4
Posting Yak Master

100 Posts

Posted - 2012-05-03 : 07:31:13
adding these exta sort cols helped me solve this, thanks for your help
Go to Top of Page
   

- Advertisement -