---
title: "The dynamic SQL discussion is a must read"
url: "https://osherove.com/blog/2003/11/18/the-dynamic-sql-discussion-is-a-must-read.md"
canonical: "https://osherove.com/blog/2003/11/18/the-dynamic-sql-discussion-is-a-must-read.html"
published: "2003-11-18T21:13:00"
updated: "2003-11-18T21:13:00"
tags: [".Net Quotations"]
author: "Roy Osherove"
description: "There's one of those “holy wars” going on in the blogsphere. This time it is about the using Dynamic SQL vs. Stored procedures. But this holy war is an important one. It's one that I have learned a lot from, and I'll…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# The dynamic SQL discussion is a must read

By Roy Osherove November 18, 2003 In [.Net Quotations](https://osherove.com/blog/category/net-quotations)

**Historical article** · Originally published November 18, 2003; technical details may be outdated.

There's one of those “holy wars” going on in the blogsphere. This time it is about the using Dynamic SQL vs. Stored procedures. But this holy war is an important one. It's one that I have learned a lot from, and I'll admit it shamelessly. I didn't know all those good things about Dynamic SQL. I really didn't I guess it's that kid of experience that you can learn form others who have done a great deal more than you in that area, and I am not a database guru by all means.

I did have the misconception that dynamic SQL is bad and that stored procedures are the cure(albeit painful at times) to the ills of SQL injection and program maintenance.

[Rob howard started it](http://weblogs.asp.net/rhoward/posts/38095.aspx) (oh god that sounds awful) and got lots of very insightful comments (read them). Then [Frans Bouma followed](http://weblogs.asp.net/fbouma/posts/38178.aspx) with a scathing and to the point response and these have been other responses in the blogsphere. Then [Rob answerd back to Frans](http://weblogs.asp.net/RHoward/posts/38298.aspx) . I urge you to read the whole discussion, as it is enlightening.

I always thought of dynamic SQL as a plague because I only knew the “bad”way of doing it: concatenating strings into WHERE clauses. I admit that I was **not aware** of the possibility to use  **sp\_executesql** and actually creating parameters in the strings passed. That makes the whole situations different when I think of it. You should read the discussion mainly because if there's one thing to “get” from all this is that there is no silver bullet. There are pros and cons for each way of doing things, but you need to have both of these tools on your belt. I really regret not having exposed myself to this earlier.

A very nice article that explains the dynamic SQL approach is [found here](http://www.algonet.se/~sommar/dyn-search.html) and here is [the blog that points to it](http://radio.weblogs.com/0101986/stories/2003/11/12/whenDidDynamicSqlGetSuchABadName.html) which contains some time comparisons of these approaches(via [Rob howard](http://weblogs.asp.net/RHoward/)).

Ah.. I fulfilled my mantra for today: “Finish the day with at least one thing you did not know before it started”

## More in .Net Quotations

[All posts in .Net Quotations](https://osherove.com/blog/category/net-quotations)

- Nov 19, 2003

    ### [Get ready for obsolete stuff in Whidbey today](https://osherove.com/blog/2003/11/19/get-ready-for-obsolete-stuff-in-whidbey-today.html)

- Nov 19, 2003

    ### [SQLTeam rules: Cool tip + cool RSS feed= goodness in the blogsphere](https://osherove.com/blog/2003/11/19/sqlteam-rules-cool-tip-cool-rss-feed-goodness-in-the-blogsph.html)

- Nov 12, 2003

    ### [Using NAnt? Download NAntPad - for visual NAnt build configuration](https://osherove.com/blog/2003/11/12/using-nant-download-nantpad-for-visual-nant-build-configurat.html)

- Nov 12, 2003

    ### [Great SQL tip: @@IDENTITY==bad, scope\_identity()==good](https://osherove.com/blog/2003/11/12/great-sql-tip-identitybad-scope_identitygood.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
