How to get records till a specific date in SQL Server? [Resolved]

Posted by Sheonarayan under Sql Server on 12/17/2012 | Points: 10 | Views : 2587 | Status : [Administrator] | Replies : 2
Hello everybody,

I have a database table (sql server) in which there is a field called "TillDate" of Date type and it is nullable.

If date is present in the record, I want to get that record only when the date is less than today's date, if date is not present or null I want that record too.

Can anybody help me in writing Sql statement for this?

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com



Responses

Posted by: Pandians on: 12/17/2012 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Please try this...!
Create Table Sample1

(
Slno Int Identity(1,1),
Column1 Varchar(10) Null,
TillDate DateTime Null
)

Insert Sample1(Column1, TillDate) Values('Aequea', '2012-12-17 15:34:33.417')
Insert Sample1(Column1) Values('Salino')
Insert Sample1(Column1, TillDate) Values('Calcalino', '2012-12-15 15:34:33.417')
Insert Sample1(Column1) Values('Setaceo')
Insert Sample1(Column1, TillDate) Values('Socaprio', '2012-12-11 15:34:33.417')
Insert Sample1(Column1, TillDate) Values('Alumino', '2012-12-15 15:34:33.417')
Insert Sample1(Column1, TillDate) Values('Vitriolic', '2012-12-17 15:34:33.417')
Go

Select * from Sample1 Where (Tilldate < GETDATE() Or Tilldate is Null)
Go


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Sheonarayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 12/17/2012 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Thank you so much Pandians, you are a SQL Server HERO.



Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sheonarayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response