Author |
Topic |
tt350z
Starting Member
5 Posts |
Posted - 2013-03-13 : 10:48:19
|
Hello Gentleman, I am drawing a blank and I was wondering if anyone could help, I am trying to write a query that picks two dates or to make it easier say the last 60 days from current date and put a value of 1 if its true and 0 if not so example today is 3/13/2013 so I need everything for last 60 days and tomorrow when query runs again it should add one day +1 and drop the last day. Hopefully that's clear it not I can try to again :) THANK YOU!!!!! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-13 : 11:03:01
|
do you've a calendar table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tt350z
Starting Member
5 Posts |
Posted - 2013-03-13 : 11:10:43
|
Yes I do - To_Char(INFORMENT.PRODUCT_OFFER_PURCHASE.DATE_ADDED, 'YYYYMMDD') |
|
|
tt350z
Starting Member
5 Posts |
Posted - 2013-03-13 : 11:13:00
|
quote: Originally posted by tt350z Yes I do - To_Char(INFORMENT.PRODUCT_OFFER_PURCHASE.DATE_ADDED, 'YYYYMMDD')
Its the daily transactions that get stored in that format. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-13 : 11:21:22
|
i'm asking on table not on column------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tt350z
Starting Member
5 Posts |
Posted - 2013-03-13 : 11:34:52
|
ohh sorry actual date table no and I cant add one...its a 3rd party database.select * from yourTable where [Date] <= dateadd(day,-60, cast(getdate() as date)) -- assuming you're using SQL 2008This will select all older dates.If you need to select last 2 months, then change your condition this wayselect * from YourTablewhere [Date]>=dateadd(day,-60, cast(getdate() as date)but it doesnt like the dateadd function.this is the only date I have access too To_Char(INFORMENT.PRODUCT_OFFER_PURCHASE.DATE_ADDED, 'YYYYMMDD'), |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-13 : 11:54:25
|
To_char? are you using Oracle? if yes, then you're in wrong forum. This is ms sql server forum so solutions posted here may not work well in oracle. You may be better off trying your luck in some oracle forums like www.orafaq.com in that case------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tt350z
Starting Member
5 Posts |
Posted - 2013-03-13 : 12:00:38
|
Its SQL& oracle but ill give that a try thanks lot :) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-13 : 12:44:06
|
Oracle SQL is syntactically different from T-SQL of sql server------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-13 : 12:44:07
|
Oracle SQL is syntactically different from T-SQL of sql server------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|