I want to know the charindex of single quote(char(39))

  • Hello friends

    I want to know the charindex of single quote whose ascii is 39 from Given string

    Like below

    Declare @strTest as VARCHAR(100)

    set @strTest = ab'c

    select charindex(CHAR(39),convert(varchar,@strTest))

  • don't convert the varchar, as you'll get truncation issues if you don't say how large to convert to;

    the rest is just syntax; you need to escape the single quote to make the variable have the value.

    this returns 3 for the charindex:

    Declare @strTest as VARCHAR(100)

    set @strTest = 'ab''c'

    select charindex(CHAR(39),@strTest)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply