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)
 casting month column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rama108
Yak Posting Veteran

72 Posts

Posted - 05/17/2012 :  16:11:39  Show Profile  Reply with Quote
Hello All,
I have the following query:

I am storing the start month in a variable called @StartMonth. Then I want to cast 'month1' as the month in the @StartMonth

select ISNULL(AVG(month1),0) AS DATENAME(month,@StartMonth)

The date store is 'Jul 1 2008 12:00AM', so you can also try the following, but it complains: "incorrect syntac near 'month'. What is wrong with the following?

select ISNULL(AVG(month1),0) AS DATENAME(month,'Jul 1 2008 12:00AM')

Thank you,
Rama

rama108
Yak Posting Veteran

72 Posts

Posted - 05/17/2012 :  16:57:40  Show Profile  Reply with Quote
I figured out the solution. It was very simple but my brain was not working:

Set @Mth1 = DATENAME(month,@StartDate)

and then use @Mth1 in my dynamic query.
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