views:

1086

answers:

1

I have a t-sql statement like Replace(field,'\''','\"') because i have two different results ''field1'' and "field2" but what if i consider those two different results the same and want to group them. I choose to group those two by replacing the first double quotes with the second style but although replaced they are not interpreted as the same type of quote.

What I am missing here??

Edited: I am trying to group data where text is the same but quotes differ, user is entering two single quotes ''hello'' and one double quote "hello", if I have this two rows I am trying to display them as one as "hello", so by executing the above statement I think I should be able to do this, but it isn't working properly even without slashes.

+3  A: 

look at this code:

DECLARE @X  varchar(20)
SET @X='''''Hello"'

PRINT @X
PRINT REPLACE(@X,'''''','"')
PRINT REPLACE(REPLACE(@X,'''''',''''),'"','''')

here is the output:

''Hello"
"Hello"
'Hello'

SQL Server does not escape quotes with slashes, a single quote is escaped with another single quote. This will print one single qoute:

print ''''

this will print two single quotes:

print ''''''
KM