Click here to Skip to main content
15,889,651 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Table Grouping Pin
Paul Conrad20-Aug-12 6:22
professionalPaul Conrad20-Aug-12 6:22 
AnswerRe: SQL Table Grouping Pin
Blue_Boy20-Aug-12 22:15
Blue_Boy20-Aug-12 22:15 
AnswerRe: SQL Table Grouping Pin
i.j.russell20-Aug-12 23:47
i.j.russell20-Aug-12 23:47 
GeneralRe: SQL Table Grouping Pin
milo-xml21-Aug-12 3:03
professionalmilo-xml21-Aug-12 3:03 
GeneralRe: SQL Table Grouping Pin
i.j.russell21-Aug-12 3:53
i.j.russell21-Aug-12 3:53 
GeneralRe: SQL Table Grouping Pin
milo-xml21-Aug-12 4:42
professionalmilo-xml21-Aug-12 4:42 
AnswerRe: SQL Table Grouping Pin
Niladri_Biswas21-Aug-12 22:26
Niladri_Biswas21-Aug-12 22:26 
AnswerRe: SQL Table Grouping Pin
__TR__21-Aug-12 22:28
__TR__21-Aug-12 22:28 
Hi,
Here is one approach. Hope this helps.

CREATE TABLE #Temp
(
ID INT IDENTITY(1,1),
[PI] INT,
JobID INT,
FormID INT,
ShiftID INT,
StartEvent DATETIME,
SW INT,
SG INT,
EndEvent DATETIME,
EG INT,
EW INT
)


INSERT INTO #Temp
SELECT 3, 9249, 36208, 6241, '2010-08-14 10:00:15.610', 0, 0, '2010-08-14 10:14:52.000', 143, 109 UNION
SELECT 3, 9249, 36208, 6241, '2010-08-14 10:14:52.217', 109, 143, '2010-08-14 10:15:04.000', 150, 109 UNION
SELECT 3, 9249, 36208, 6241, '2010-08-14 10:15:04.763', 109, 150, '2010-08-14 10:15:07.000', 150, 109 UNION
SELECT 3, 9249, 36208, 6241, '2010-08-14 10:15:09.820', 109, 150, '2010-08-14 10:29:15.000', 150, 221 UNION
SELECT 3, 9249, 36208, 6241, '2010-08-14 10:29:15.570', 221, 150, '2010-08-14 10:53:09.000', 376, 300 UNION
SELECT 3, 9249, 36208, 6241, '2010-08-14 10:53:09.240', 300, 376, '2010-08-14 11:01:18.000', 4294, 1824 UNION
SELECT 3, 9249, 36208, 6241, '2010-08-14 11:01:18.553', 1824, 4294, '2010-08-14 11:02:06.000', 4294, 1942 UNION
SELECT 3, 9249, 36208, 6241, '2010-08-14 11:02:06.363', 1942, 4294, '2010-08-14 11:02:14.000', 4294, 1920 



SELECT T1.*, T2.EndEvent, T2.EG, T2.EW FROM
(
	SELECT T.[PI], T.JobID, T.FormID, T.ShiftID, T.StartEvent, T.SW, T.SG FROM #Temp T
	INNER JOIN
	(
		SELECT MIN(ID) AS MinID, [PI], JobID, FormID, ShiftID FROM #Temp
		GROUP BY [PI], JobID, FormID, ShiftID
	) X ON T.ID = X.MinID 
) T1
INNER JOIN
(
	SELECT T.[PI], T.JobID, T.FormID, T.ShiftID, T.EndEvent, T.EG, T.EW FROM #Temp T
	INNER JOIN
	(
		SELECT MAX(ID) AS MaxID, [PI], JobID, FormID, ShiftID FROM #Temp
		GROUP BY [PI], JobID, FormID, ShiftID
	) X ON T.ID = X.MaxID 
) T2 ON T1.[PI] = T2.[PI] AND T1.JobID = T2.JobID AND T1.FormID = T2.FormID AND T1.ShiftID = T2.ShiftID 


DROP TABLE #Temp

AnswerRe: SQL Table Grouping Pin
milo-xml22-Aug-12 7:54
professionalmilo-xml22-Aug-12 7:54 
AnswerRe: SQL Table Grouping Pin
Michael Potter23-Aug-12 6:16
Michael Potter23-Aug-12 6:16 
Questionssis database reocords to execel sheet Pin
vasu1219-Aug-12 18:56
vasu1219-Aug-12 18:56 
Questionconverting console base application to windows form Pin
shaikh-adil17-Aug-12 7:45
shaikh-adil17-Aug-12 7:45 
AnswerRe: converting console base application to windows form Pin
Eddy Vluggen17-Aug-12 7:57
professionalEddy Vluggen17-Aug-12 7:57 
GeneralMessage Closed Pin
17-Aug-12 8:03
shaikh-adil17-Aug-12 8:03 
GeneralRe: converting console base application to windows form Pin
Paul Conrad17-Aug-12 8:27
professionalPaul Conrad17-Aug-12 8:27 
GeneralMessage Closed Pin
17-Aug-12 8:36
shaikh-adil17-Aug-12 8:36 
GeneralRe: converting console base application to windows form Pin
Paul Conrad17-Aug-12 9:21
professionalPaul Conrad17-Aug-12 9:21 
SuggestionRe: converting console base application to windows form Pin
Eddy Vluggen17-Aug-12 10:17
professionalEddy Vluggen17-Aug-12 10:17 
GeneralMessage Closed Pin
17-Aug-12 19:37
shaikh-adil17-Aug-12 19:37 
GeneralRe: converting console base application to windows form Pin
Eddy Vluggen17-Aug-12 23:02
professionalEddy Vluggen17-Aug-12 23:02 
GeneralMessage Closed Pin
18-Aug-12 5:28
shaikh-adil18-Aug-12 5:28 
GeneralRe: converting console base application to windows form Pin
Eddy Vluggen18-Aug-12 5:53
professionalEddy Vluggen18-Aug-12 5:53 
AnswerRe: converting console base application to windows form Pin
PIEBALDconsult17-Aug-12 9:46
mvePIEBALDconsult17-Aug-12 9:46 
GeneralRe: converting console base application to windows form Pin
Paul Conrad17-Aug-12 11:06
professionalPaul Conrad17-Aug-12 11:06 
AnswerRe: converting console base application to windows form Pin
WebMaster17-Aug-12 12:09
WebMaster17-Aug-12 12:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.