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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Find Previous available date

Author  Topic 

MageshkumarM
Yak Posting Veteran

61 Posts

Posted - 2013-02-08 : 02:42:29
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

61 Posts

Posted - 2013-02-08 : 02:43:49
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

22864 Posts

Posted - 2013-02-08 : 02:52:00
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

61 Posts

Posted - 2013-02-08 : 03:40:30
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

61 Posts

Posted - 2013-02-08 : 04:52:34
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

52326 Posts

Posted - 2013-02-08 : 05:12:45
[code]
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
[/code]

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

Go to Top of Page

MageshkumarM
Yak Posting Veteran

61 Posts

Posted - 2013-02-08 : 05:43:05
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

52326 Posts

Posted - 2013-02-08 : 05:55:23
welcome

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

Go to Top of Page
   

- Advertisement -