How to exec SQL instruction stored in @variable

  • DmitryIlyushenko

    SSC Rookie

    Points: 37

    Does anybody know how can I execute SQL instruction that stored in local variable. For example @var='SELECT AuthorName from Authors'. Variable stoging gives me ability to create dynamic queries.

  • Sean Burke

    SSCommitted

    Points: 1504

    Check out sp_executesql in SQL Server's Books On Line. This allows you to execute a sql statement or batch that you have built. An alternative would be to use the EXECUTE statement.

    Sean

Viewing 2 posts - 1 through 2 (of 2 total)

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