If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > cursor help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-05, 14:21
breed16 breed16 is offline
Registered User
 
Join Date: Oct 2004
Posts: 4
cursor help

I want to qualify date1 from a date field from of table1 and then use the date1 to qualify a second select statment on table2. I'm confused on how to handle the declare statment and then open the cursor in the second statement. any help would be appreicated. thanks.

my example is

@mydate1 = select date1 from table1
select * from table2 where date2 = @mydate1
Reply With Quote
  #2 (permalink)  
Old 01-19-05, 14:38
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
select * from table2 where date2 = (select date1 from table1)

If there is more than value retrieved (even if the multiple values are equal) in the subselect then change the = to IN. Or use a select distinct if the multiple values are equal in the subselect.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 01-19-05, 14:59
breed16 breed16 is offline
Registered User
 
Join Date: Oct 2004
Posts: 4
yes I understand the subselect statment works the same way,
but that's not what I'm looking for, I'm looking for the right way to declare and the then reference a cursor.
thanks
Reply With Quote
  #4 (permalink)  
Old 01-19-05, 15:06
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
That depends entirely on what programming language or procedure you are using. You want to store the output of a query in a host variale and then use the host variable in the next query.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 01-19-05, 15:23
breed16 breed16 is offline
Registered User
 
Join Date: Oct 2004
Posts: 4
I guess what I'm looking to do is come up with a type of session or temporary variable that can be altered based on what sepcific time period the users are looking for. for the end users who are writing sql against db2 on unix.
by declaring or creating a variable/Alias upfront and then referencing the vairable thru out the code, I'm hoping to gain a better access paths against the database server instead of joining to multiple tables.
Reply With Quote
  #6 (permalink)  
Old 01-19-05, 16:02
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Are you wanting to use the sql in a unix script, C program, stored procedure, etc? Please explain. It makes a difference.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #7 (permalink)  
Old 01-19-05, 16:25
breed16 breed16 is offline
Registered User
 
Join Date: Oct 2004
Posts: 4
the end users typicaly use business object to build and automate their reports.
Reply With Quote
  #8 (permalink)  
Old 01-19-05, 17:04
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
So, it's either ODBC or JDBC... I guess you can't do what you want in plain SQL. You could create a stored proc that returns a resultset to the caller and pass the date to that stored proc; however I'm not sure BusinessObjects can invoke stored procedures...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On