• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Replace certain text within row

I have a table with multiple rows like this:
if not exists (select * from dbo.sysusers where name = N'GA\ggalligan') Exec sp_grantdbaccess N'GA\GA\ggalligan', N'GA\ggalligan'

I need to remove the first GA\ where it says GA\GA\ggalligan.  All the rows are different lengths, so it always can't start in the same place. This needs to be an update statement.  Any help would be much appreciated.
0
tbailey2011
Asked:
tbailey2011
1 Solution
 
exile1337Commented:
export rows to xls and use replace with function to change the text. Afterwards import back to SQL.

0
 
tbailey2011Author Commented:
This is something that has to be automated everyday thru a sql query or that would work.
0
 
Scott PletcherSenior DBACommented:
UPDATE table
SET col = REPLACE(col, ' N''GA\GA\', ' N''GA\')
WHERE col LIKE '% N''GA\GA\%'
0
 
tim_csCommented:
I would run this as a select to make sure it gives you the desired results first.

UPDATE YourTable
SET YourFieldName = STUFF(YourFieldName,CHARINDEX('GA\',YourFieldName),3,'')
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now