February 21, 2012 at 9:05 am
select Name,Block_Name,BlockType, HOURS , Month,cast((DP.Hours*PH.pp)as decimal(4,0))as tt1,PH.PP,
case Month when 'january' then 1
when 'february' then 2
when 'march' then 3
when 'april' then 4
when 'may' then 5
when 'june' then 6
when 'july' then 7
when 'august' then 8
when 'september' then 9
when 'october' then 10
when 'november' then 11
when 'december' then 12 end as mnth
from ##temp1 DP, ##cmd_holiday PH where
DP.MOnth = PH.MOnths
this query is giving me months compare i wanna compare year also over here ..can u temme how i can do this ...am not so good wid date functions
February 21, 2012 at 9:13 am
It's not clear what you are trying to do. Have you looked at the datepart functions?
February 21, 2012 at 9:14 am
from your query so far, i couldn't infer any datetime columns exist that you could pull the year out of.
there is a YEAR function that will get the year of a datetime column that can help.
assuming the column "CreatedDate" exists(your column name is ??), you would simply add to your WHERE clause:
AND YEAR(DP.CreatedDate) = YEAR(PH.CreatedDate)
Lowell
February 21, 2012 at 9:21 am
with this query am getting months only for a single year - 2012 if user selects from
march to dec
i would get
march - 3
april-4
........
till december - 12
what happens if user selects from
nov -2011 to march -2012
am getting bad data here
nov - 2011
nov - 2012
dec -2011
dec - 2012
the correct representation should be
nov - 2011
dec -- 2011
nov - 2012
dec -2012
now ?? canu help me how ?
February 21, 2012 at 9:37 am
try this:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
should help to get the most relevant answer in minutes.
February 21, 2012 at 9:57 am
Eugene Elutin (2/21/2012)
try this:http://www.sqlservercentral.com/articles/Best+Practices/61537/
should help to get the most relevant answer in minutes.
link from above updated: the link had an extra
character in it after the forum rendered it.
Lowell
February 21, 2012 at 10:00 am
February 21, 2012 at 12:29 pm
sqlcentral2 (2/21/2012)
with this query am getting months only for a single year - 2012 if user selects frommarch to dec
i would get
march - 3
april-4
........
till december - 12
what happens if user selects from
nov -2011 to march -2012
am getting bad data here
nov - 2011
nov - 2012
dec -2011
dec - 2012
the correct representation should be
nov - 2011
dec -- 2011
nov - 2012
dec -2012
now ?? canu help me how ?
I am only guessing based on the lack on information, but you may be ordering by the month only and not the year first (then month). Or you have month first in your "order by".
+100 on what the others said though...you have to give us more info to ensure that we aren't guessing when trying yo help you.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply