zach
zach

Reputation: 1361

conditions in Case statement

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.

Upvotes: 1

Views: 80

Answers (3)

gbn
gbn

Reputation: 432230

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

select
    min(measurement),
    RIGHT('0000000000' + part_desc, 10) AS part_desc
from...

Upvotes: 4

AllenG
AllenG

Reputation: 8190

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...

Upvotes: 1

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171411

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

Upvotes: 1

Related Questions