Friday, March 9, 2012

Problem with replace function

Hi,

Please find the below scenario

Original Table

course branch_exist
BY0
UI1
PO1
LI0
MK1

select REPLACE(branch_exist,1,'yes') as branch from university;

displays

course branch_exist
BY0
UIYes
POYes
LI0
MKYes

What i need is

course branch_exist
BYNo
UIYes
POYes
LINo
MKYes

Sql-Server replace function only accepts three arguments, any
suggestions will be greatly welcomed!What i need is:

Quote:

Originally Posted by

course branch_exist
BY No
UI Yes
PO Yes
LI No
MK Yes


select
CAST branch_exist
WHEN 1 THEN 'yes'
WHEN 0 'no'
ELSE '?' END as branch
from university;

--
Tom
http://kbupdate.info/ | http://suppline.com/|||Oops, typo happens. Right version is:

select
CASE branch_exist
WHEN 1 THEN 'yes'
WHEN 0 THEN 'no'
ELSE '?'
END as branch
from university;

--
Tom
http://kbupdate.info/ | http://suppline.com/|||On Apr 9, 5:37 pm, "kb" <a...@.kbupdate.infowrote:

Quote:

Originally Posted by

Oops, typo happens. Right version is:
>
select
CASE branch_exist
WHEN 1 THEN 'yes'
WHEN 0 THEN 'no'
ELSE '?'
END as branch
from university;
>
--
Tomhttp://kbupdate.info/|http://suppline.com/


Hi Kb,

Thanks you !

No comments:

Post a Comment