dbTalk Databases Forums  

update SQL field with stripped data from other field

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


Discuss update SQL field with stripped data from other field in the comp.databases.ms-sqlserver forum.



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

Default update SQL field with stripped data from other field - 05-12-2006 , 01:31 PM






Not a SQL guy but can do enough to be dangerous

Trying to update a record. We have records that have a field with data
surrounded by some comment text such as *** Previous Public Solution
*** Start and *** Previous Public Solution *** End . What I am trying
to do is write a SQL statement that will:

Check that field C100 = TICKET0001 (to test with one record before
running on whole db)
Check that field C101 is = Closed
Check that field C102 is null
Copy field C103 data to field C102 and strip out any words such as ***
Previous Public Solution *** Start and *** Previous Public Solution
*** end

Thanks for any help!
Kevin


Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: update SQL field with stripped data from other field - 05-12-2006 , 05:17 PM






geekwagon (prourl (AT) gmail (DOT) com) writes:
Quote:
Not a SQL guy but can do enough to be dangerous

Trying to update a record. We have records that have a field with data
surrounded by some comment text such as *** Previous Public Solution
*** Start and *** Previous Public Solution *** End . What I am trying
to do is write a SQL statement that will:

Check that field C100 = TICKET0001 (to test with one record before
running on whole db)
Check that field C101 is = Closed
Check that field C102 is null
Copy field C103 data to field C102 and strip out any words such as ***
Previous Public Solution *** Start and *** Previous Public Solution
*** end
UPDATE tbl
SET C102 = replace(replace(C103,
'*** Previous Public Solution *** Start',
'*** Previous Public Solution *** end))
WHERE C100 = 'TICKET0001'
AND C101 = 'Closed'
AND C102 IS NULL

This assumes that the text is exactly as you posted, and with no
variation in spacing etc. I would guess that real world is different.
Unfortunately that can be difficult to handle in SQL. If you are on
SQL 2005 you could possible write a CLR that works with regular
expressions. Else the cleanup is probably best done client-side.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


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.