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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to specify "Current Year" plus May 1st?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MCusuma1
Starting Member

11 Posts

Posted - 08/14/2012 :  10:50:58  Show Profile  Reply with Quote
I have been trying to write a script that pulls data from a table and places it into a new table with a WHERE statement that indicates [CURRENT YEAR]\05\01. Here is what I have tried as a test to see if I can get the syntax to work in an independent query:


CREATE TABLE DATE(C1 datetime2, C2 varchar)
INSERT INTO DATE(C1)
VALUES (CONVERT (datetime2, CONVERT(varchar, year(getdate())) + "05-01 00:00:00.0000000"))

Edited by - MCusuma1 on 08/14/2012 10:52:13

visakh16
Very Important crosS Applying yaK Herder

India
48076 Posts

Posted - 08/14/2012 :  10:53:33  Show Profile  Reply with Quote
INSERT INTO DATE(C1)
SELECT DATEADD(yy,DATEDIFF(yy,0,GETDATE()),'19000501')
...

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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48076 Posts

Posted - 08/14/2012 :  10:57:56  Show Profile  Reply with Quote
see logic here

http://visakhm.blogspot.com/2012/07/generate-datetime-values-from-integers.html

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

Go to Top of Page

MCusuma1
Starting Member

11 Posts

Posted - 08/14/2012 :  11:09:11  Show Profile  Reply with Quote
Thanks I'll try that.
Go to Top of Page

MCusuma1
Starting Member

11 Posts

Posted - 08/14/2012 :  11:26:10  Show Profile  Reply with Quote
Worked like a charm thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48076 Posts

Posted - 08/14/2012 :  12:48:40  Show Profile  Reply with Quote
welcome

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

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 08/16/2012 :  10:38:53  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Also
SELECT dateadd(month,5-1,dateadd(year,year(getdate())-1900,0))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 08/16/2012 :  10:40:39  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by MCusuma1

I have been trying to write a script that pulls data from a table and places it into a new table with a WHERE statement that indicates [CURRENT YEAR]\05\01. Here is what I have tried as a test to see if I can get the syntax to work in an independent query:


CREATE TABLE DATE(C1 datetime2, C2 varchar(specify size))
INSERT INTO DATE(C1)
VALUES (CONVERT (datetime2, CONVERT(varchar, year(getdate())) + "05-01 00:00:00.0000000"))


See here for reason
http://beyondrelational.com/modules/2/blogs/70/posts/10824/column-length-and-data-length.aspx

Madhivanan

Failing to plan is Planning to fail
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.06 seconds. Powered By: Snitz Forums 2000