Pergunta

I have data like this:

State   ID
-----   --
'CA'    5
'CA'    3
'MA'    2
'NH'    1
'NJ'    8
'NH'    9

For all the states it is putting apostrophes around the states.

I'm looking to somehow search by the state abbreviation but it won't let me search like this:

where state=''CA'' 

...because it's closing each apostrophe with the one after it.

I also tried this:

substring(state,charindex(''',state)+1),
    charindex(''',state)-charindex(''',state),+1)
Foi útil?

Solução

Try this. I believe this is what you are wanting...

Where state like '''CA''%'

It is better to do it this way because you can use indexes. If you apply a function against the column, it must apply that against the entire table.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top