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 > Simple SQL Assistance needed - runtime variables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-04, 10:31
AS400Admin AS400Admin is offline
Registered User
 
Join Date: Aug 2003
Posts: 39
Simple SQL Assistance needed - runtime variables

Hello List,
I am trying to run the following SQL on the AS400 (either as a standalone query or an stored proc, but I can't get it to work. Something similar works in MS SQL...can someone tell me what I need to do differently on the AS400?
DECLARE CURDATE CHAR(6),
DECLARE BEGDATE CHAR(6),

SET CURDATE = SELECT MAX(SHUPMJ) FROM SYS7333.F3912
SET BEGDATE = SELECT (MAX(SHUPMJ) - 7) FROM SYS7333.F9312

SELECT * FROM SYS7333.F9312
WHERE SHEVTYP = '01' AND SHEVSTAT = '02'
AND (SHUPMJ BETWEEN begdate AND curdate)
ORDER BY SHUPMJ, SHUPMT, SHUSER;
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 01:58
hurmavi hurmavi is offline
Registered User
 
Join Date: Jan 2004
Location: Europe, Finland, Helsinki
Posts: 60
Re: Simple SQL Assistance needed - runtime variables

Hmmh...

I'm NOT an AS/400 expert, but why dont you try something like this:

SELECT * FROM SYS7333.F9312
WHERE SHEVTYP = '01' AND SHEVSTAT = '02'
AND (SHUPMJ BETWEEN
(SELECT (MAX(SHUPMJ) - 7) FROM SYS7333.F9312)
AND
(SELECT MAX(SHUPMJ) FROM SYS7333.F3912)
)
ORDER BY SHUPMJ, SHUPMT, SHUSER;

Cheers, Bill
Reply With Quote
  #3 (permalink)  
Old 04-15-04, 10:39
AS400Admin AS400Admin is offline
Registered User
 
Join Date: Aug 2003
Posts: 39
Re: Simple SQL Assistance needed - runtime variables

Quote:
Originally posted by hurmavi
Hmmh...

I'm NOT an AS/400 expert, but why dont you try something like this:

SELECT * FROM SYS7333.F9312
WHERE SHEVTYP = '01' AND SHEVSTAT = '02'
AND (SHUPMJ BETWEEN
(SELECT (MAX(SHUPMJ) - 7) FROM SYS7333.F9312)
AND
(SELECT MAX(SHUPMJ) FROM SYS7333.F3912)
)
ORDER BY SHUPMJ, SHUPMT, SHUSER;

Cheers, Bill
Bill, I am having one of those moments where I feel like an idiot...

I'm not sure why the subquery didn't occur to me.

Thanks so much.

Ryan
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