Click here to Skip to main content
15,919,245 members
Home / Discussions / Database
   

Database

 
GeneralRe: how to start Schema design? Pin
Niladri_Biswas23-Aug-12 19:58
Niladri_Biswas23-Aug-12 19:58 
AnswerRe: how to start Schema design? Pin
Eddy Vluggen24-Aug-12 22:29
professionalEddy Vluggen24-Aug-12 22:29 
QuestionFind phonetic word in SQL Pin
chandra reinhart23-Aug-12 5:07
chandra reinhart23-Aug-12 5:07 
AnswerRe: Find phonetic word in SQL Pin
Pete O'Hanlon23-Aug-12 5:29
mvePete O'Hanlon23-Aug-12 5:29 
GeneralRe: Find phonetic word in SQL Pin
chandra reinhart11-Sep-12 19:56
chandra reinhart11-Sep-12 19:56 
AnswerRe: Find phonetic word in SQL Pin
Niladri_Biswas23-Aug-12 19:42
Niladri_Biswas23-Aug-12 19:42 
GeneralRe: Find phonetic word in SQL Pin
chandra reinhart11-Sep-12 19:53
chandra reinhart11-Sep-12 19:53 
QuestionSQL Table Grouping Pin
milo-xml20-Aug-12 3:56
professionalmilo-xml20-Aug-12 3:56 
AnswerRe: SQL Table Grouping Pin
David Mujica20-Aug-12 4:54
David Mujica20-Aug-12 4:54 
GeneralRe: SQL Table Grouping Pin
milo-xml20-Aug-12 6:19
professionalmilo-xml20-Aug-12 6:19 
AnswerRe: SQL Table Grouping Pin
Paul Conrad20-Aug-12 6:26
professionalPaul Conrad20-Aug-12 6:26 
GeneralRe: SQL Table Grouping Pin
milo-xml20-Aug-12 6:36
professionalmilo-xml20-Aug-12 6:36 
AnswerRe: SQL Table Grouping Pin
Paul Conrad20-Aug-12 6:43
professionalPaul Conrad20-Aug-12 6:43 
GeneralRe: SQL Table Grouping Pin
milo-xml20-Aug-12 8:45
professionalmilo-xml20-Aug-12 8:45 
GeneralRe: SQL Table Grouping Pin
Paul Conrad20-Aug-12 8:52
professionalPaul Conrad20-Aug-12 8:52 
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 
Hope this may help (Sql Server 2000+)

SQL
Declare @t table(PI int, JobID int, FormID int, ShiftID int, StartEvent datetime, SW int,SG  int, EndEvent datetime,EG int,EW int)
Insert Into @t
Select 3,9249,36208,6241,'2010-08-14 10:00:15.610',0,0,'2010-08-14 10:14:52.000',143,109 Union All
Select 3,9249,36208,6241,'2010-08-14 10:14:52.217',109,143,'2010-08-14 10:15:04.000',150,109 Union All
Select 3,9249,36208,6241,'2010-08-14 10:15:04.763',109,150,'2010-08-14 10:15:07.000',150,109 Union All
Select 3,9249,36208,6241,'2010-08-14 10:15:09.820',109,150,'2010-08-14 10:29:15.000', 150,221 Union All
Select 3,9249,36208,6241,'2010-08-14 10:29:15.570', 221,150,'2010-08-14 10:53:09.000',376,300 Union All
Select 3,9249,36208,6241,'2010-08-14 10:53:09.240',300,376,'2010-08-14 11:01:18.000',4294,1824 Union All
Select 3,9249,36208,6241,'2010-08-14 11:01:18.553',1824,4294 ,'2010-08-14 11:02:06.000',4294,1942 Union All
Select 3,9249,6208,6241,'2010-08-14 11:02:06.363',1942,4294,'2010-08-14 11:02:14.000',4294,1920

Select X.*,Y.EndEvent,Y.EG,Y.EW
From(  Select Top 1 PI,JobID,FormID,ShiftID,StartEvent,SW,SG
        From @t
        Order By StartEvent)X
Join ( Select Top 1 PI,EndEvent,EG,EW
        From @t
        Order By EndEvent DESC)Y
On X.PI = Y.PI



Result
PI	JobID	FormID	ShiftID	StartEvent	SW	SG	EndEvent	EG	EW
3	9249	36208	6241	2010-08-14 10:00:15.610	0	0	2010-08-14 11:02:14.000	4294	1920

Niladri Biswas
(Code Project MVP 2012)

AnswerRe: SQL Table Grouping Pin
__TR__21-Aug-12 22:28
__TR__21-Aug-12 22:28 
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 

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.