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
 General SQL Server Forums
 New to SQL Server Programming
 How to find value for specific date

Author  Topic 

VKor
Starting Member

1 Post

Posted - 2012-01-19 : 07:33:09
I have a next table:
Name SalDate Salary
Irene 2000-01-01 8000
Bob 2000-01-01 8500
Bob 2001-01-11 9000
Irene 2005-01-07 9000
Bob 2008-01-05 12000
Irene 2008-01-10 11000
David 2010-01-03 14000
Bob 2010-01-11 15000

To create:
create
table #TmpTbl
(Name nvarchar(50),
SalDate date,
Salary int)

insert into #TmpTbl
values
('Irene', '01-01-2000', 8000),
('Bob', '01-01-2000', 8500),
('Bob', '01-11-2001', 9000),
('Irene', '01-07-2005', 9000),
('Bob', '01-05-2008', 12000),
('Irene', '01-10-2008', 11000),
('David', '01-03-2010', 14000),
('Bob', '01-11-2010', 15000)

A question is:
What was Bob's salary at 01-12-2007?

Thanks for any help!

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-19 : 07:36:05
[code]SELECT TOP 1
Salary
FROM
#TmpTbl
WHERE
NAME= 'Bob'
AND SalDate < '20071201'
ORDER BY
SalDate DESC[/code]
Go to Top of Page
   

- Advertisement -