SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get records that have a valid date range for today
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Tookum
Starting Member

2 Posts

Posted - 08/19/2013 :  15:04:45  Show Profile  Reply with Quote
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

India
649 Posts

Posted - 08/19/2013 :  15:14:03  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
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

Sweden
30249 Posts

Posted - 08/19/2013 :  15:40:59  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000