Skip to content
Home » Dynamic SQL

Dynamic SQL

Using SUBSTRING based on line number instead of character offset

Suppose we’re running one or more dynamic SQL commands in SQL Server, and we’re getting an error from somewhere within it.

But, to make things interesting, let’s suppose that we’re running a large number of such dynamic SQL commands within a loop, each constructed a bit differently, and we’re finding it difficult to pinpoint which of the dynamic commands is causing the error, and which SQL statement it is exactly.

Could we, perhaps, print the relevant code section based on the error line reported in the CATCH block?

Webinar: Advanced Dynamic Search Queries and How to Protect Them

First of all, I must apologize for the long hiatus since my last published content.
I’ve been busy working on a lot of very different stuff, and unfortunately this delayed me from actually completing any one particular thing.

One thing that I did complete, though, was preparing and submitting a webinar for the PASS Global Hebrew Virtual Group.

The webinar is called “Advanced Dynamic Search Queries and How to Protect Them”, and I will be presenting it on Tuesday, April 30th 2019, 13:00 UTC (15:00 Israel Time).

Let SQL Server Write Code for You

A lot of DBAs would spend hours (and even days) sitting in front of their computer to write a stupendous amount of lines of code… Then take care of a lot of copy-paste and typing errors… Test the code and find errors… Fix the code… Run it again… And so on. All the while having to navigate within a huge forest of code.

I would presume that it doesn’t take a special kind of mind to stand up and say “just hold on a minute! Why am I working so hard with this mundane task?? Why can’t SQL Server do all of this for me??”

Because in fact… It can!

Read More »Let SQL Server Write Code for You