General discussion

  • Creator
    Topic
  • #2343841

    Exec SQL String in SQL Serv. Stored Proc

    Locked

    by frankus ·

    Is there a way to execute a SQL String in a SQL Server 7.0 Stored Procedure.

All Comments

  • Author
    Replies
    • #3691869

      Exec SQL String in SQL Serv. Stored Proc

      by andrew ·

      In reply to Exec SQL String in SQL Serv. Stored Proc

      No problem.
      Use Exec (execute) to run the built up SQL string:

      Create Proc pListNames (@FieldName varchar(128),@FieldValue varchar(128))as
      exec (‘select * from authors where ‘ + @FieldName + ‘ = ‘ + “‘” + @FieldValue + “‘”)

      exec pListNames ‘au_lname’,’white’

      (If you’re passing in string values, remember to wrap them in single quotes once they’re in the proc)

      The downside to this is that SQL Server can’t compile the proc, so performance is poorer.

    • #3612129

      Exec SQL String in SQL Serv. Stored Proc

      by frankus ·

      In reply to Exec SQL String in SQL Serv. Stored Proc

      This question was closed by the author

Viewing 1 reply thread