Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 searched case function

Author  Topic 

smccreadie
Aged Yak Warrior

505 Posts

Posted - 2003-01-22 : 12:15:33
My code:

 		CASE rfqty
WHEN LEN(a.rfqty)=1 THEN '0000'+ CAST(a.rfqty AS CHAR(1))
WHEN LEN(a.rfqty)=2 THEN '000'+ CAST(a.rfqty AS CHAR(2))
WHEN LEN(a.rfqty)=3 THEN '00'+ CAST(a.rfqty AS CHAR(3))
WHEN LEN(a.rfqty)=4 THEN '0'+ CAST(a.rfqty AS CHAR(4))
ELSE CAST(a.rfqty as char(5))
END


I get a syntax error on the "="

I've done this many times before but can't see the error. Anyone see it?



mfemenel
Professor Frink

1421 Posts

Posted - 2003-01-22 : 12:24:50
wouldn't you need to write it this way:

case len(rfqty)
when 1 then '0000' + cast(a.rfqty as char(1))




Mike
"oh, that monkey is going to pay"
Go to Top of Page

smccreadie
Aged Yak Warrior

505 Posts

Posted - 2003-01-22 : 12:28:05
Of course, how dumb of me.

Thanks for the quick help.

Go to Top of Page

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2003-01-22 : 12:39:54
Of course this is easier to read

RIGHT('00000' + CAST(a.rfqty AS VARCHAR), 5)

Go to Top of Page
   

- Advertisement -