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
 Getting list Of Data for Current Week
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mahesh.sanka
Starting Member

India
18 Posts

Posted - 03/12/2013 :  05:58:52  Show Profile  Reply with Quote

Hi ,

In my project i have one column Policy Expiry Date which is a Date Field.

for Example

Policy Expiry Date Policy Number
------------------- ----------------
2012-03-14 00:00:00.000 A143
2089-10-31 00:00:00.000 A326
2076-11-06 00:00:00.000 A1234
2078-11-19 00:00:00.000 A4567
2012-12-01 00:00:00.000 A12345

I want to get list of the ploicies which are expiring in the current week.


Thanks & Regards,
Mahesh Kumar Sanka

bandi
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 03/12/2013 :  06:38:35  Show Profile  Reply with Quote
DECLARE @ploicy TABLE(PolicyExpiryDate DATETIME, PolicyNumber VARCHAR(6))
INSERT INTO @ploicy
SELECT '2012-03-14 00:00:00.000', 'A143' union all
SELECT '2089-10-31 00:00:00.000', 'A326' union all
SELECT '2076-11-06 00:00:00.000', 'A1234' union all
SELECT '2078-11-19 00:00:00.000', 'A4567' union all
SELECT '2013-03-14 00:00:00.000', 'A12345'
--I want to get list of the ploicies which are expiring in the current week.
SELECT PolicyNumber,DATEPART(wk, PolicyExpiryDate), DATEPART(wk, GETDATE())
FROM @ploicy
WHERE DATEPART(wk, PolicyExpiryDate) = DATEPART(wk, GETDATE())
AND DATEPART(yy, PolicyExpiryDate) = DATEPART(yy, GETDATE())

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/12/2013 :  06:44:28  Show Profile  Reply with Quote
better way to write it is

SELECT PolicyNumber,DATEPART(wk, PolicyExpiryDate), DATEPART(wk, GETDATE())
FROM @ploicy
WHERE PolicyExpiryDate > = DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
AND PolicyExpiryDate < DATEADD(wk,DATEDIFF(wk,0,GETDATE())+1,0)


see

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.11 seconds. Powered By: Snitz Forums 2000