Reputation: 21742
OK so I'm a bit rusty on parts of T-SQL such as string manipulation I got a string in a field called [path] the value of the field could look like
'foo\Branches\Bar\Baz\Helpers\FileNotFoundResult.cs'
I need to update the field (for all records) so that the result will be
'Branches\Bar\Baz\Helpers\FileNotFoundResult.cs'
that is strip of anything before the first '\' and the '\'
so I'd appricate if any one could help me fill in the "blanks"
UPDATE SourceFiles
SET Path = <blanks>
Upvotes: 0
Views: 588
Reputation: 239636
Something like
UPDATE SourceFiles
SET Path = SUBSTRING(Path,CHARINDEX('\',Path)+1,8000)
(Assuming your Path column isn't a varchar(max))
If your path column might not contain a backslash at all, you might want:
UPDATE SourceFiles
SET Path = CASE
WHEN CHARINDEX('\',Path) = 0 THEN Path
ELSE SUBSTRING(Path,CHARINDEX('\',Path)+1,8000)
END
Upvotes: 3