• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 747
  • Last Modified:

DATENAME showing same date across all rows

Why is DateName showing all January when I know it's not.  If I remove DateName, I get numbers for each month like 1,4,2,5 which should be converted to varying month names but they're all coming out 'January'

SELECT  DISTINCT m.customer,
          c.name,
          c.customer,
          (SELECT Top 1 fd.Fee1 FROM FSch fd
                    where c.FSch = fd.code)
          AS FSch,
          m.Branch,
          CASE WHEN ph.bgg = 'U' OR ph.btype = 'R' OR ph.bgg = 'P' OR ph.bgg = 'D' Then
                      (-ph.tpaid + ph.oFee)
              ELSE
                      (ph.tpaid - ph.oFee)
          END AS [Amount],
            DATENAME(m, ph.systemmonth) as systemmonth,
          ph.systemyear
.....
0
dba123
Asked:
dba123
  • 2
  • 2
1 Solution
 
rafranciscoCommented:
Looks like your systemmonth only contains the numeric month value and not a whole date value.  If this is the case, you can do the following:

SELECT  DISTINCT m.customer,
          c.name,
          c.customer,
          (SELECT Top 1 fd.Fee1 FROM FSch fd
                    where c.FSch = fd.code)
          AS FSch,
          m.Branch,
          CASE WHEN ph.bgg = 'U' OR ph.btype = 'R' OR ph.bgg = 'P' OR ph.bgg = 'D' Then
                      (-ph.tpaid + ph.oFee)
            ELSE
                      (ph.tpaid - ph.oFee)
          END AS [Amount],
          DATENAME(m, CAST(CAST(ph.systemmonth AS VARCHAR(2)) + '/01/2006' AS DATETIME)) as systemmonth,
          ph.systemyear
0
 
LowfatspreadCommented:
SELECT  DISTINCT m.customer,
          c.name,
          c.customer,
          (SELECT Top 1 fd.Fee1 FROM FSch fd
                    where c.FSch = fd.code)
          AS FSch,
          m.Branch,
          CASE WHEN ph.bgg in  ('U' ,'R', 'P',= 'D') Then
                      (-ph.tpaid + ph.oFee)
            ELSE
                      (ph.tpaid - ph.oFee)
          END AS [Amount],
          DATENAME(m, '2006'+right('0'+convert(varchar(2),ph.systemmonth)+'01',2)) as systemmonth,
          ph.systemyear
.....
0
 
dba123Author Commented:
lowfatspread..that now shows June all the way down...
0
 
dba123Author Commented:
>>>Looks like your systemmonth only contains the numeric month value and not a whole date value

yes, that's what I was saying..correct
0
 
LowfatspreadCommented:
sorry

  DATENAME(m, '2006'+right('0'+convert(varchar(2),ph.systemmonth),2)+'01') as systemmonth,
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now