3

Can you please guide me why dynamic SQL is suggested to avoid ? Is there any way that I can keep on using dynamic SQL and avoid its bad things ?

Ozair Kafray
  • 13,351
  • 8
  • 59
  • 84
user576510
  • 5,777
  • 20
  • 81
  • 144

2 Answers2

4

http://www.sommarskog.se/dynamic_sql.html

If you don't understand everything in this, come back and ask a question, but under no circustances should you use dynamic SQl until you understand this article.

HLGEM
  • 94,695
  • 15
  • 113
  • 186
1

The main problem is sql injection. People can enter data that can change the intent of your sql.

One of the best solutions is to use sp_executesql. http://msdn.microsoft.com/en-us/library/ms188001.aspx

Scott Bruns
  • 1,971
  • 12
  • 12