tags:

views:

41

answers:

4

I have a query, say Select foo from bar Foo is a string field, and will always start with "http://". I want to replace "http://" with "xml://" during the select, so all foo values come back as xml://..., instead of http://... Is there a way to substitute on the fly, during the query?

+3  A: 

Look at the REPLACE keyword. Alternatively if you need to do more complex porcessing than replace can handle, Look at CASE.

HLGEM
+8  A: 
SELECT REPLACE(column, 'http://', 'xml://') FROM ...
ar
A: 

A simple REPLACE will do

SELECT REPLACE(YourColumn,'http://','xml://') FROM YourTable
SQLMenace
+3  A: 

As you know it's always at the beginning at the string and presumably have integrity constraints to verify this!

SELECT STUFF(column,1,4,'xml') FROM ...

Edit: In fact why are you storing the protocol at all in that case? You could just store the rest of the URL and append whatever protocol you need without having to strip out a superfluous substring.

Martin Smith