0

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)
Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
Jt2ouan
  • 1,964
  • 9
  • 33
  • 55

1 Answers1

0

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.

UnhandledExcepSean
  • 12,504
  • 2
  • 35
  • 51