Beginning of year

Good morning,
  I need to be able to calculate from the beginning of the current year every year to get year to date information.

What is the SQL statement for this.

I'll be placeing ion a SP or DTS SQl statement.
Thanks,
lrbrister
Larry Bristersr. DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

muzzy2003Commented:
Beginning of current year:

CAST(CAST(YEAR(GETDATE()) AS varchar(10)) + '-01-01' AS datetime)

Is that what you wanted?
0
Duane LawrenceCommented:
declare @string varchar(100)
select @string = datepart(yyyy,getdate())
select DateDiff(dd, '01-01-'+@string, getdate())

Duane
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
muzzy2003Commented:
Good afternoon, by the way, where I am!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Larry Bristersr. DeveloperAuthor Commented:
muzzy2003,
I tried your statement in Query Analyzer and got the error message below


CAST(CAST(YEAR(GETDATE()) AS varchar(10)) + '-01-01' AS datetime)

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'CAST'.
0
muzzy2003Commented:
Duane's code gives you the day number in the year. But you can get this more directly with:

DATEPART(dayofyear, GETDATE())
0
muzzy2003Commented:
This is a fragment, not a statement. Stick a SELECT in front of it to see it working.
0
muzzy2003Commented:
... technically an "expression", I guess!
0
acharbonneauCommented:
'muzzy2003,
'I tried your statement in Query Analyzer and got the error message below

'CAST(CAST(YEAR(GETDATE()) AS varchar(10)) + '-01-01' AS datetime)

'Server: Msg 170, Level 15, State 1, Line 1
'Line 1: Incorrect syntax near 'CAST'.



You can't just evaluate the expression, you need to do something with the result of it.

try this:

            print  CAST(CAST(YEAR(GETDATE()) AS varchar(10)) + '-01-01' AS datetime)

0
Larry Bristersr. DeveloperAuthor Commented:
duanelawrence,
  Yours is what I'm looking for right now. Points being awarded now.

 It appears that the '01-01' joins itself to the @string  for the beginning of any year and gets the difference between itself and the getdate() statement...correct?

I have to do a lot of annualization and that number is what I need in my calculations.

Thanks.
0
Duane LawrenceCommented:
lrbrister

Yes, that is correct.  I should have put a comment in to explain what I was doing.  Thanks for the points.

Dua
0
muzzy2003Commented:
So isn't DATEPART(dayofyear, GETDATE()) what you want then?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.