Tuesday, October 31, 2006

Paramterizing queries using sp_get_query_template

Ken Henderson, my SQL hero, has an interesting post about parameterizing queries. This is useful when, for example, you want to use the text returned from the Profiler and then take out the hard coded strings - turning them into parameters for easy re-use.

The sp_get_query_template stored proc takes the text of a query as a parameter, then returns the normalized text and the parameter list as output parameters. Although it was not designed for general query normalization, this gets you as close as you currently can get to invoking SQL Server’s own code to normalize your queries.

Ken Henderson's WebLog : Normalizing query text

No comments: