Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Testsubjec
Starting Member
1 Post |
Posted - 2011-06-24 : 09:13:33
|
Hi all,I wonder if you can help.We a field in SQL szNotes, this can contain as example "Please contact David Jones on 333442333 before delivery AM TL".What I am after in doing is this:First, the codes need to be replaced with actual codes relavent to our system.I.e. AM = DEL BY 12:00, A1 = DEL BY 12:00, TL = T/L, B1 = BD, B2 = BD, B3 = BD: + szDeliveryTime.Once these codes have be replaced, the replaced codes need to be then put at the beginning of the string.Example: "BEL BY 12:00 T/L Please contact David Jones on 333442333 before delivery AM TL".I have got the SQL to look for the codes and replace them but I cannot figure out how to put them at the beginning.Any help would be much appreicated.Thanks |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-06-24 : 09:42:43
|
One way to do it would be something like this:DECLARE @var VARCHAR(255);SET @var = 'Please contact David Jones on 333442333 before delivery AM TL';SELECT CASE WHEN @var LIKE '% AM TL' THEN 'DEL BY 12:00 T/L ' + REPLACE(@var,' AM TL','') CASE WHEN @var LIKE '% PM TL' THEN 'DEL AFTER 12:00 T/L ' + REPLACE(@var,' AM TL','') -- etc. END If you don't want to remove the AM TL at the end, instead of "REPLACE(@var,' AM TL','')", just use "@var" |
 |
|
|
|
|
|
|