1
select min(measurement), part_desc
    (case len(measurement)
        when 6 then '0000' + part_desc
        else '000' + part_desc
        end)
from LeachingView
where DateTimeStamp > '2011-01-01' and measurement > 0
group by measurement, part_desc

That is suppposed to append 0000's to the front of another char, but it doesn't work, and i was wondering why and how to make it correct.

The error I get is this:

'part_desc' is not a recognized built-in function name.

gbn
  • 422,506
  • 82
  • 585
  • 676
zach
  • 1,281
  • 7
  • 27
  • 41

3 Answers3

4

Don't really need a CASE at all...

select
    min(measurement),
    RIGHT('0000000000' + part_desc, 10) AS part_desc
from...
gbn
  • 422,506
  • 82
  • 585
  • 676
1
select min(measurement), 
    case len(measurement)
        when 6 then '0000' + part_desc
        else '000' + part_desc
    end as part_desc
from LeachingView
where DateTimeStamp > '2011-01-01' 
    and measurement > 0                        
group by case len(measurement)
        when 6 then '0000' + part_desc
        else '000' + part_desc
    end
D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
1

I think you want

Select min(measurment),
       (case len(measurement)
         when 6 then '0000' + part_desc
         else '000' + part_desc
        end) AS "part_desc"
From LeachingView
Where...
AllenG
  • 8,112
  • 29
  • 40