Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
Variables in SQL
Sagitt
Hi all,
I have a very simple sql query that uses date_from and date_to in WHERE clause. Every day I run my query I have to change dates. Is this possible to use variables instead of 'hard coded' dates?
I would like define one variable as today's date and second variable as today - 7 days. How do go around this?
I use Teradata sql, not sure exactly if that does make any difference for sql.
regards,
Sagitt
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
Mort5000
Teradata Forum
Looks like there is a system calendar utility table/view there to help you out.
FSL
Use a combination of Datediff and Gedate in your query. i.e the difference in days between the date in the table and the current date is less than 7 will give you today and the previous 6 days use less than 8 if you want today and the previous seven days.
DublinWriter
There should be a date variable that you can use.
In Oracle it would be simply:
select * from table where sale_date >= sysdate -7 and sale_date <= sysdate
All DBMS have a current date variable that you should be able to use.