Sunday, February 14, 2010

Replace String in SQL Query (SQL Server Replase)

Exp: #1
Select replace(((Col_name)), '-', '==') as filtercol from tablname


Exp: #2
SELECT REPLACE('AsmA Qureshi Software Developer','Software Developer','Project Manager') as AQCOL

S.No      AQCOL
-------  -----------------------------
1         AsmA Qureshi Project Manager-------  -----------------------------

Exp: #3
SELECT
 REPLACE('Banana', REPLACE('Orange', REPLACE('Banana', Product, 'Fruit'),
          'Fruit'), 'Fruit') AS Product
FROM
 Table


Product     Quantity
-------     --------
Apple       2
Orange      3
Banana      1
Vegetable   7
Dairy       6

would become


Product     Quantity
-------     --------
Fruit       2
Fruit       3
Fruit       1
Vegetable   7
Dairy       6

Exp Query 
SELECT
 REPLACE('Banana', REPLACE('Orange', REPLACE('Banana', Product, 'Fruit'),
          'Fruit'), 'Fruit') AS Product
FROM
 Table

No comments:

Post a Comment