By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Get previous record before given date SQL Query problem

P: 1
Hi,

I have a table PeopleCategory, with the following fields
id int,
PersonID int,
CategoryCode nvarchar(10),
date datetime

This table holds the history of the persons 'category codes'. what I need is some SQL which will allow me to get a list of 'category codes' for the persons in the table on a specified date.

Can any one please help

Thanks in advance,

Peter Tewkesbury
Jan 28 '08 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
Hi,

I have a table PeopleCategory, with the following fields
id int,
PersonID int,
CategoryCode nvarchar(10),
date datetime

This table holds the history of the persons 'category codes'. what I need is some SQL which will allow me to get a list of 'category codes' for the persons in the table on a specified date.

Can any one please help

Thanks in advance,

Peter Tewkesbury
select * from PeopleCategory where id = 999 and date = cast(somedate as datetime)

more on where

-- ck
Jan 28 '08 #2

deepuv04
Expert 100+
P: 227
select * from PeopleCategory where id = 999 and date = cast(somedate as datetime)

more on where

-- ck

Since your datatype for date column is datetime it has time stamp along with it, so the above query may not work for you....


try the following query to get the records on specific date

select * from TABLE_NAME where DATEDIFF(DAY,date,SPECIFIED_DATE) = 0

here we are finding the date difference between the date column value and given date if 0 means that record is on the given date...

thanks
Jan 29 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.