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
 Get records that have a valid date range for today

Author  Topic 

Tookum
Starting Member

2 Posts

Posted - 2013-08-19 : 15:04:45
Hi

I want to get all records that have a valid date range for todays date(20130819).
All records have a date_f and date_t. I need to check that against todats date. The below code is my version of sql pseudo code.
Any help appreciated. :-)

Thanks


SELECT DISTINCT
p.id,
p.name,
c.ip_number
FROM
tbl_Person AS p, tbl_current_conn_ipnumber AS c
WHERE
c.id=p.id
AND
check if today is between date_f and date_t
(TODAY()>=date_f AND TODAY()=<date_t)
ORDER BY p.id, p.name;


tbl_Person
id name
a243 Jim Samson
a144 Greg Roberts
a631 William Hanson

tbl_current_conn_ipnumber
id date_f time_f date_t time_t ip_number
a243 20130817 0000 20130818 1200 172.16.254.1
a144 20130817 0534 20130818 0800 172.16.253.10
a243 20130818 2105 20130819 1800 172.16.133.1

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2013-08-19 : 15:14:03
SELECT DISTINCT
p.id,
p.name,
c.ip_number
FROM
tbl_Person AS p, tbl_current_conn_ipnumber AS c
WHERE
c.id=p.id
AND
convert(varchar(10),getdate(),112) between convert(varchar(10),date_f,112) and convert(varchar(10),date_t,112)
ORDER BY p.id, p.name;

mohammad.javeed.ahmed@gmail.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-19 : 15:40:59
WHERE CAST(GETDATE() AS DATE) BETWEEN Date_F AND Date_T



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -