Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Find Previous available date
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MageshkumarM
Yak Posting Veteran

India
61 Posts

Posted - 02/08/2013 :  02:42:29  Show Profile  Reply with Quote
Hi all,

I hav a datas below mentioned


2010-01-01 JackSon 25.6
2010-01-02 Stack 230.1
2010-01-04 Steven 23.1
2010-01-05 Bell 2.11
2010-01-07 Clerk 30.1
2010-01-08 June 1.1

I'm try to find previous date, could please help me abt this.


MageshkumarM
Yak Posting Veteran

India
61 Posts

Posted - 02/08/2013 :  02:43:49  Show Profile  Reply with Quote
I'm trying to retrieve date = '2010-01-07' and i expect previous day date.

Thanks,
Magesh.M
http://mageshkumarm.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22864 Posts

Posted - 02/08/2013 :  02:52:00  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
where date_col>=dateadd(day,datediff(day,0,getdate()),-1) and date_col<dateadd(day,datediff(day,0,getdate()),0)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

MageshkumarM
Yak Posting Veteran

India
61 Posts

Posted - 02/08/2013 :  03:40:30  Show Profile  Reply with Quote
sorry, where the condition check with date '2010-01-07'.

I'm not get the previous day date..

Thanks,
Magesh.M
http://mageshkumarm.blogspot.com/
Go to Top of Page

MageshkumarM
Yak Posting Veteran

India
61 Posts

Posted - 02/08/2013 :  04:52:34  Show Profile  Reply with Quote
any one help me out of this


Thanks,
Magesh.M
http://mageshkumarm.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/08/2013 :  05:12:45  Show Profile  Reply with Quote

SELECT Datefield AS YourDate,t1.PrevDate AS PreviousDate
FROM YourTable t
OUTER APPLY (SELECT MAX(DateField) AS PrevDate
             FROM YourTable
             WHERE datefield < t.Datefield)t1


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

Go to Top of Page

MageshkumarM
Yak Posting Veteran

India
61 Posts

Posted - 02/08/2013 :  05:43:05  Show Profile  Reply with Quote
make sense this statement.. thk u so much

Thanks,
Magesh.M
http://mageshkumarm.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/08/2013 :  05:55:23  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next 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.03 seconds. Powered By: Snitz Forums 2000