1

in SQL Server we denote unicode string literals thus:

declare @s nvarchar(max)
select @s = N'test'

however, we can also use double quotes... so we should be able to do this:

set quoted_identifier off
declare @s nvarchar(max)
select @s = N"test"

but there I've gone wrong:

Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'test'.

what is the correct form?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
ekkis
  • 9,804
  • 13
  • 55
  • 105

2 Answers2

0

In T-SQL, you can use the double-quote to specify the name of a column in a SELECT statement, in the same way use can use square brackets [].

Compare

select 1 as "value x"
select 1 as [value x]

both resulting in a column named value x.

For string literals, only '' and N'' can be used.

Update after comment from Nikola

The MSDN page on T-SQL constants mentions the QUOTED_IDENTIFIER/double-quote/single-quote behavior only for "character string constants", but the section "Unicode strings" only refers to the N'' notation.

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
devio
  • 36,858
  • 7
  • 80
  • 143
  • 1
    Not quite, OP uses [set quoted_identifier off](http://msdn.microsoft.com/en-us/library/ms174393%28v=sql.105%29.aspx) to alter this behaviour. The question is why are we not allowed to specify unicode constant using double quotes. – Nikola Markovinović Sep 17 '12 at 22:07
  • 1
    Oh, thank you @Nikola. Right answer to the wrong question, then ;) – devio Sep 17 '12 at 22:52
0

You can't use double-quotes to delimit Unicode character strings in T-SQL.

So what? What's the problem you're trying to solve?

You can still embed single-quotes within a Unicode string by doubling them up.

SELECT N'This isn''t a problem'
GilM
  • 3,711
  • 17
  • 18
  • The problem is that we might have a large amount of text with many single quotes in it and it is much easier to double-quote the whole thing. This is not an answer to the question. – Lukos Mar 14 '17 at 14:24
  • It *is* an answer to the question. The desired syntax is just incorrect and double-quotes can't be used with Unicode literals. And, there is a workaround. If it's difficult to double-up the single-quotes manually, then use the Find/Replace function of SSMS (or whatever editor) and replace each ' with two of them within the selected text. – GilM Sep 04 '18 at 07:11