0

I have two queries, first one is the regular SELECT and the other one is an EXEC query as what I mentioned below:

  1. SELECT * FROM [table] WHERE [column] = 'test'

and

  1. EXEC(' SELECT * FROM [table] WHERE [column] = ''test'' ')

as for the results, I tried to execute both queries in sql server 2008 and i was given the exact same outputs, if both queries return the same output then what's the purpose of the single quote and double single quotes in sql?

illimite
  • 99
  • 1
  • 13
  • 7
    Careful, 2 single quotes isn't a double quote. – EzLo May 14 '18 at 13:44
  • Doubled single quotes are normally used for quoting, e.g. `insert into foo (f1) values ('O''brian')` – thebjorn May 14 '18 at 13:45
  • 2
    I have this feeling that your actual `EXEC` is `EXEC( 'SELECT * FROM [table] WHERE [column] = ''test''' )` And surely there you can see the difference. When you have a single quote in a string literal you have to escape it with a second single quote: So `variable='this is a ''test'''` sets `variable` to `this is a 'test'` – JNevill May 14 '18 at 13:45
  • oh yeah sorry my bad it's actually `EXEC( 'SELECT * FROM [table] WHERE [column] = ''test''' )` @JNevill – illimite May 14 '18 at 13:49

0 Answers0