Archive for SQL/T-SQL

Using the “Replace” Function in Sql Server/T-SQL

I ran into an issue today where I needed to strip two characters out of a field while in a stored procedure.  The string looked something like this:

@UserID = {abcdefghi}

I needed the middle text (abcdefgi) only so I used the replace function.  The replace function only allows you to replace one thing at a time so I had to use it twice.  This is what the end result looks like:


Ugly, yes, but it gets the job done.