IUnknown
IUnknown

Reputation: 9839

Conditional REPLACE in SQL Server

The table project contains

projectid|description|statuscode|path|....

I have a SQL clause which should return the following (pseudocode):

SELECT ...,  
     CASE   
     WHEN statusCode IN ('C', 'N', 'F') 
       IF (path contains 'CLOSED PROJECTS')
       THEN   
        REPLACE(path,'CLOSED PROJECTS','DEAD PROJECTS') 
       ELSE
        REPLACE(path,'ACTIVE PROJECTS','DEAD PROJECTS') 
,
.....
from Project where projectId=..... 

How do I implement this 'conditional' REPLACE?

I am using SQL Server 2008.

Upvotes: 0

Views: 11250

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93754

May be like this..

SELECT ...,  
 CASE   
 WHEN statusCode IN ('C', 'N', 'F') 
   and path like '%CLOSED PROJECTS%'
   THEN   
    REPLACE(path,'CLOSED PROJECTS','DEAD PROJECTS') 
   ELSE
    REPLACE(path,'ACTIVE PROJECTS','DEAD PROJECTS') 
,
.....
from Project where projectId=..... 

Upvotes: 3

Related Questions