BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help me?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Bpk. Adi Wira Kusuma
Guest





PostPosted: Mon Jul 25, 2005 2:03 am    Post subject: Help me? Reply with quote



I've data like this

noid fdate ftime fstatus
---------------------------------------
1 1/1/2005 1/1/2005 6:30:00 1
1 1/1/2005 1/1/2005 6:30:00 1
1 1/1/2005 1/1/2005 6:31:00 1
1 1/1/2005 1/1/2005 16:30:00 1
1 1/1/2005 1/1/2005 16:30:00 0
1 1/1/2005 1/1/2005 16:33:00 0
1 1/1/2005 1/1/2005 16:33:00 0
2 1/1/2005 1/1/2005 6:27:00 1
2 1/1/2005 1/1/2005 6:28:00 1
2 1/1/2005 1/1/2005 6:32:00 1
2 1/1/2005 1/1/2005 16:30:00 0
2 1/1/2005 1/1/2005 16:31:00 0
2 1/1/2005 1/1/2005 16:45:00 0
2 1/1/2005 1/1/2005 16:45:00 0

I want to delete. if fstatus =1 so fisrt record (min(Ftime)) of group
noid,fdate is not deleted. but if fstatus =0 so last record (max(Ftime)) of
group noid,fdate is not deleted. So its data will be;

noid fdate ftime fstatus
---------------------------------------
1 1/1/2005 1/1/2005 6:30:00 1
1 1/1/2005 1/1/2005 16:33:00 0
2 1/1/2005 1/1/2005 6:27:00 1
2 1/1/2005 1/1/2005 16:45:00 0

Can u help me? How sintax sql? Can it be solved with one statement?



Back to top
Yannis
Guest





PostPosted: Mon Jul 25, 2005 5:57 am    Post subject: Re: Help me? Reply with quote



"Bpk. Adi Wira Kusuma" <adi_wira_kusuma (AT) yahoo (DOT) com.sg> wrote in
news:42e44c73 (AT) newsgroups (DOT) borland.com:

Quote:
Can u help me? How sintax sql? Can it be solved with one statement?


Try the following sql

Delete From Table1 T1 where (FStatus = 1 and FTime >(Select min(Ftime) from
Table1 T2 Where T2.noid = T1.noid and T2.Fdate = T1.Fdate)) OR (FStatus = 0
and FTime < (Select max(Ftime) from Table1 T3 Where T3.noid = T1.noid and
T3.Fdate = T1.Fdate))

I think it will do the job

Disclaimer :
The above statement has been keyed in directly to the news client and never
tested on any sql server. It has been written with a background of MSSQL
server and I do not know if it will work on any other server.
Changes probably required in order to make it work for your purposes.

Regards
Yannis.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.