SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 SQL help - Drawing blank
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tt350z
Starting Member

5 Posts

Posted - 03/13/2013 :  10:48:19  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 03/13/2013 :  11:03:01  Show Profile  Reply with Quote
do you've a calendar table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tt350z
Starting Member

5 Posts

Posted - 03/13/2013 :  11:10:43  Show Profile  Reply with Quote
Yes I do - To_Char(INFORMENT.PRODUCT_OFFER_PURCHASE.DATE_ADDED, 'YYYYMMDD')
Go to Top of Page

tt350z
Starting Member

5 Posts

Posted - 03/13/2013 :  11:13:00  Show Profile  Reply with Quote
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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/13/2013 :  11:21:22  Show Profile  Reply with Quote
i'm asking on table not on column

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tt350z
Starting Member

5 Posts

Posted - 03/13/2013 :  11:34:52  Show Profile  Reply with Quote
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 2008
This will select all older dates.

If you need to select last 2 months, then change your condition this way

select * from YourTable
where [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'),
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/13/2013 :  11:54:25  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

tt350z
Starting Member

5 Posts

Posted - 03/13/2013 :  12:00:38  Show Profile  Reply with Quote
Its SQL& oracle but ill give that a try thanks lot :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/13/2013 :  12:44:06  Show Profile  Reply with Quote
Oracle SQL is syntactically different from T-SQL of sql server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/13/2013 :  12:44:07  Show Profile  Reply with Quote
Oracle SQL is syntactically different from T-SQL of sql server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000