Ian R. O'Brien
Ian R. O'Brien

Reputation: 6920

How can I compare with a single apostrophe in SQL to see if a column starts with an apostrophe?

Basically I am trying to trim the left-most character if and only if it as an apostrophe.

My script is as follows

Identifier =
    CASE
        WHEN LEFT(Identifier, 1) = '' -- I think this is wrong
            THEN RIGHT(Identifier, LEN(Identifier) - 1) ELSE Identifier
        END,

What I want to do is remove the first character if and only if it is an apostrophe but I don't know how to perform the comparison with the single quote.

This is in SQL Server 2008.

Upvotes: 1

Views: 146

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1270573

Try this:

when left(identifier, 1) = ''''

Upvotes: 1

cha
cha

Reputation: 10411

try this:

LEFT(Identifier, 1) = ''''

Upvotes: 2

Related Questions