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 > Date variables/Functions for DB2 in SQL DTS

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-15-10, 15:17
VegaLA VegaLA is offline
Registered User
 
Join Date: Sep 2006
Posts: 26
Date variables/Functions for DB2 in SQL DTS

Good day everyone.
I have a SQL DTS package that runs the following code and pulls the Data from an AS400 table to a SQL table. This all works rather well but i'd rather use a date function to determine the Data rather then havign to change the hard coded part on a monthly basis. The criteria looks like this:-

WHERE
(AS400Table.AS400Field BETWEEN 20100301 AND 20100331)
or
(AS400Table.AS400Field BETWEEN 20100216 and 20100315)


In SQL if I wanted to run this the WHERE clause would look like this:-

WHERE
((AS400Table.AS400Field BETWEEN dateadd(mm, datediff(mm, 0, getdate()) - 2, 0) AND SELECT dateadd(mm, datediff(mm, 0, getdate()) +1, -1))
or
((AS400Table.AS400Field BETWEEN SELECT dateadd(mm, datediff(mm, 0, getdate()) - 1, +15) AND SELECT dateadd(mm, datediff(mm, 0, getdate()) , +14))

Since the data is being pulled from AS400 the syntax will not work, can anyone assist me in automating this Data range so I can pull the correct Data from AS400 please?

Thanks in advance,
Mitch....
Reply With Quote
  #2 (permalink)  
Old 03-15-10, 15:40
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,230
something like this:
Code:
between 
  current_date - day(current_date) + 1 days
and
  current_date + 1 month - day(current_date + 1 month) days
I guess you can figure out the other one by yourself.
Reply With Quote
  #3 (permalink)  
Old 03-15-10, 19:58
VegaLA VegaLA is offline
Registered User
 
Join Date: Sep 2006
Posts: 26
Thanks Nick.
I edited the DTS SQL query using BETWEEN current_date - day(current_date) + 1 days AND current_date + 1 month - day(current_date + 1 month) days) and the error message I get is as follows:

SQL0182 - A Date, time , or timestamp expression not valid.

I'm not sure if this is because AS400 keeps the date as '20100216' ?

Any ideas?

Thanks,
Mitch....
Reply With Quote
  #4 (permalink)  
Old 03-15-10, 20:47
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,230
Try "current date" instead of "current_date"
Reply With Quote
  #5 (permalink)  
Old 03-15-10, 20:49
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,230
By the way, here's the manual: iSeries Information Center
Reply With Quote
  #6 (permalink)  
Old 03-15-10, 21:44
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 1,830
Quote:
WHERE
(AS400Table.AS400Field BETWEEN 20100301 AND 20100331)
or
(AS400Table.AS400Field BETWEEN 20100216 and 20100315)
What is a data type of AS400Table.AS400Field?

Try
BETWEEN current_date - (day(current_date) + 1) days AND current_date + 1 month - day(current_date + 1 month) days

If you want this month(e.g. BETWEEN '2010-03-01' AND '2010-03-31'), try
BETWEEN current_date - (day(current_date) - 1) days AND current_date + 1 month - day(current_date + 1 month) days
Reply With Quote
  #7 (permalink)  
Old 03-19-10, 19:53
VegaLA VegaLA is offline
Registered User
 
Join Date: Sep 2006
Posts: 26
Thanks guys.
Just checked the table out on AS400 and just discovered that the field in that table is not in fact date type but 'Numeric Zoned' so... i'll have to rethink my approach.
Sorry it took me so long to reply, been workign elsewheer but really appreciate your help!

Mitch......
Reply With Quote
  #8 (permalink)  
Old 03-19-10, 21:23
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,007
Quote:
Originally Posted by VegaLA View Post
Thanks guys.
Just checked the table out on AS400 and just discovered that the field in that table is not in fact date type but 'Numeric Zoned' so...
That is ironic because DB2 iSeries is not really DB2, so...
__________________
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
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

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