dbTalk Databases Forums  

Is this possible in sql?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Is this possible in sql? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sheldonlg
 
Posts: n/a

Default Is this possible in sql? - 05-21-2008 , 03:51 PM






I posted this in the mysql newsgroup before finding this one. My db is
oracle. So, here it is:

***************
I have a table like this: FP_YEAR, FP_MONTH, FP_STDT (with other
things in it as well) where FP means fiscal period and STDT is the start
date that goes with the year and month. Yes, it is redundant, but this
table has to interact with others where some are on year and month and
the others are on start date.

I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above. What
I want to know is whether it is possible, using that reference table, to
build my table and have ENDDT populated by looking at the next (or
previous) row. All my sql experience has been with a single row or from
the entire table. I don't know if it is possible to reference the
adjacent row.

I can pull the table out, and in php manufacture the row by doing array
manipulations. Putting it back, though, would require "n" calls unless
there is a way to update successive rows in a table, each with its own
FP_YEAR and FP_MONTH as where clause restrictions.

So, it is possible to do what I want strictly in SQL, or will I have to
go to multiple calls. Of course, I can restrict the number of return
calls by only putting into the array where FP_ENDDT is null. That would
mean I would only have the large number of calls the first time. Each
time I add a new period I would then have one (or two) calls. However,
if it is possible in SQL, I would prefer that way.

Reply With Quote
  #2  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:16 PM






sheldonlg wrote on 21.05.2008 22:51:
Quote:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above. What
I want to know is whether it is possible, using that reference table, to
build my table and have ENDDT populated by looking at the next (or
previous) row. All my sql experience has been with a single row or from
the entire table. I don't know if it is possible to reference the
adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527


Reply With Quote
  #3  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:16 PM



sheldonlg wrote on 21.05.2008 22:51:
Quote:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above. What
I want to know is whether it is possible, using that reference table, to
build my table and have ENDDT populated by looking at the next (or
previous) row. All my sql experience has been with a single row or from
the entire table. I don't know if it is possible to reference the
adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527


Reply With Quote
  #4  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:16 PM



sheldonlg wrote on 21.05.2008 22:51:
Quote:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above. What
I want to know is whether it is possible, using that reference table, to
build my table and have ENDDT populated by looking at the next (or
previous) row. All my sql experience has been with a single row or from
the entire table. I don't know if it is possible to reference the
adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527


Reply With Quote
  #5  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:16 PM



sheldonlg wrote on 21.05.2008 22:51:
Quote:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above. What
I want to know is whether it is possible, using that reference table, to
build my table and have ENDDT populated by looking at the next (or
previous) row. All my sql experience has been with a single row or from
the entire table. I don't know if it is possible to reference the
adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527


Reply With Quote
  #6  
Old   
sheldonlg
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:24 PM



Thomas Kellerer wrote:
Quote:
sheldonlg wrote on 21.05.2008 22:51:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above.
What I want to know is whether it is possible, using that reference
table, to build my table and have ENDDT populated by looking at the
next (or previous) row. All my sql experience has been with a single
row or from the entire table. I don't know if it is possible to
reference the adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527

Yes, that is EXACTLY what I am looking for. Thank you very much.


Reply With Quote
  #7  
Old   
sheldonlg
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:24 PM



Thomas Kellerer wrote:
Quote:
sheldonlg wrote on 21.05.2008 22:51:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above.
What I want to know is whether it is possible, using that reference
table, to build my table and have ENDDT populated by looking at the
next (or previous) row. All my sql experience has been with a single
row or from the entire table. I don't know if it is possible to
reference the adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527

Yes, that is EXACTLY what I am looking for. Thank you very much.


Reply With Quote
  #8  
Old   
sheldonlg
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:24 PM



Thomas Kellerer wrote:
Quote:
sheldonlg wrote on 21.05.2008 22:51:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above.
What I want to know is whether it is possible, using that reference
table, to build my table and have ENDDT populated by looking at the
next (or previous) row. All my sql experience has been with a single
row or from the entire table. I don't know if it is possible to
reference the adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527

Yes, that is EXACTLY what I am looking for. Thank you very much.


Reply With Quote
  #9  
Old   
sheldonlg
 
Posts: n/a

Default Re: Is this possible in sql? - 05-21-2008 , 04:24 PM



Thomas Kellerer wrote:
Quote:
sheldonlg wrote on 21.05.2008 22:51:
I want to add FP_ENDDT where ENDDT is either the last day before the
next period or the beginning of the next period. I don't really care
which, since I will either use "<" or "<=" for the date range.

This table is built from another one that the three fields above.
What I want to know is whether it is possible, using that reference
table, to build my table and have ENDDT populated by looking at the
next (or previous) row. All my sql experience has been with a single
row or from the entire table. I don't know if it is possible to
reference the adjacent row.
Have a look at the lag() function, that's what you are looking for:

http://download-uk.oracle.com/docs/c...0.htm#i1327527

Yes, that is EXACTLY what I am looking for. Thank you very much.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.