Running Dynamic SQL

  • Hi All,

    I have in the past created dynamic SQL in a tally table and looped through to execute it. This is probably not best practice but what alternatives are there, apart from cursors and/or while loops that could be used in this instance?

    Thanks for your thoughts

    SQL DBA
    Every day is a school day, and don't trust anyone who tells you any different.
    http://sqlblogness.blogspot.co.uk

  • Depends. What are you trying to do?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi Gail - Hope you are well.

    I spoke to you at SQL in the City In London a week or so ago (i was the one with the questions after the 'life in the day of a dba' talk on the Friday re: the windows double hop authentication issue - Good talk BTW, I recognised a lot of my day to day life.

    I sometimes have the need to run some scripts such as DBCC [x] or provide a stored procedure with a list of values to run (using existing Sproc that adds does some calcs, so I need to provide the parameters that I have obtained and put into a temp table) . I know that it would be best to achieve this via a set based method but have yet to arrive at it. Any ideas (set based, that is)?

    Thanks, Elliot

    SQL DBA
    Every day is a school day, and don't trust anyone who tells you any different.
    http://sqlblogness.blogspot.co.uk

  • Have you considered using the SSIS execute sql task? You can map parameters to it. If you need to do many somewhat independent things as a batch, add them as a steps in one job in sql server.

    ----------------------------------------------------

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply