tylercomp
tylercomp

Reputation: 901

Does '&' mean something special in sql?

I have a View in microsoft sql server management studio that uses the code

WHEN (CHARINDEX('&', page_url) > 0)

in a case statement, does the & mean something special?

Even in strings with a url that does not contain '&' it seems to be greater than 0...?

Upvotes: 0

Views: 902

Answers (3)

JustinStolle
JustinStolle

Reputation: 4440

It has no special meaning. Do a test yourself:

SELECT CHARINDEX('&', 'http://blah.com/page.html?q=one&w=another') 

Should return 32

SELECT CHARINDEX('&', 'http://blah.com/page.html?q=one')

Should return 0

The problem may lie elsewhere in your CASE statement.

Upvotes: 0

cHao
cHao

Reputation: 86535

The character '&' means nothing special, when used within a string -- it's just an ampersand. No SQL engine that i know of treats it specially. (OK, apparently Oracle does something wacky with it. But SQL server definitely doesn't, and neither does any other DBMS i've worked with.)

Upvotes: 3

Abe Miessler
Abe Miessler

Reputation: 85096

No, it should just return the index. Run this example to see:

SELECT CHARINDEX('&', 'test&test')

This returns 5 as you would expect. Can you post what string it's not returning the expected results for?

Upvotes: 1

Related Questions