dbTalk Databases Forums  

Problem with replace function

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Problem with replace function in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
meendar
 
Posts: n/a

Default Problem with replace function - 04-09-2007 , 07:02 AM






Hi,

Please find the below scenario

Original Table

course branch_exist
BY 0
UI 1
PO 1
LI 0
MK 1


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

displays

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


What i need is


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


Sql-Server replace function only accepts three arguments, any
suggestions will be greatly welcomed!


Reply With Quote
  #2  
Old   
kb
 
Posts: n/a

Default Re: Problem with replace function - 04-09-2007 , 07:34 AM






Quote:
What i need is:
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/




Reply With Quote
  #3  
Old   
kb
 
Posts: n/a

Default Re: Problem with replace function - 04-09-2007 , 07:37 AM



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/



Reply With Quote
  #4  
Old   
meendar
 
Posts: n/a

Default Re: Problem with replace function - 04-09-2007 , 08:22 AM



On Apr 9, 5:37 pm, "kb" <a... (AT) kbupdate (DOT) info> wrote:
Quote:
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 !




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.