SQL column function problem

Brian Stewart

SQL column function problem
Hello -

I want to select the most recent 30-day period of records from a
table. Conceptually I would like to do "select a from b where
b.record_created_date >= max(record_created_date) - 30 days" but this
of course will return an error due to a column function being used in
a WHERE clause.

I have been looking for an end-around to this problem but have not
found an elegant solution. Any suggestions? I know this is likely a
very simple problem, and I think I have solved it before but for some
reason it escapes me now.

Thanks in advance for any and all help -

Brian

---------------------------------------------------------------------------------
Welcome to the IDUG DB2-L list. To unsubscribe, go to the archives and home page at http://www.idugdb2-l.org/archives/db2-l.html. From that page select "Join or Leave the list". The IDUG DB2-L FAQ is at http://www.idugdb2-l.org. The IDUG List Admins can be reached at [login to unmask email] Find out the latest on IDUG conferences at http://conferences.idug.org/index.cfm

Pradeep Gunjala

Re: SQL column function problem
(in response to Brian Stewart)
Brian,

You can acheive with the following query.

select a from b where b.record_created_date >=
(select (max(record_created_date) - 30 days) from b)"

Thanks,
Pradeep

Brian Stewart <[login to unmask email]> wrote:
Hello -

I want to select the most recent 30-day period of records from a
table. Conceptually I would like to do "select a from b where
b.record_created_date >= max(record_created_date) - 30 days" but this
of course will return an error due to a column function being used in
a WHERE clause.

I have been looking for an end-around to this problem but have not
found an elegant solution. Any suggestions? I know this is likely a
very simple problem, and I think I have solved it before but for some
reason it escapes me now.

Thanks in advance for any and all help -

Brian

---------------------------------------------------------------------------------
Welcome to the IDUG DB2-L list. To unsubscribe, go to the archives and home page at http://www.idugdb2-l.org/archives/db2-l.html. From that page select "Join or Leave the list". The IDUG DB2-L FAQ is at http://www.idugdb2-l.org. The IDUG List Admins can be reached at [login to unmask email] Find out the latest on IDUG conferences at http://conferences.idug.org/index.cfm


---------------------------------
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.

---------------------------------------------------------------------------------
Welcome to the IDUG DB2-L list. To unsubscribe, go to the archives and home page at http://www.idugdb2-l.org/archives/db2-l.html. From that page select "Join or Leave the list". The IDUG DB2-L FAQ is at http://www.idugdb2-l.org. The IDUG List Admins can be reached at [login to unmask email] Find out the latest on IDUG conferences at http://conferences.idug.org/index.cfm