General discussion

Locked

Exec SQL String in SQL Serv. Stored Proc

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

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Exec SQL String in SQL Serv. Stored Proc

by andrew In reply to Exec SQL String in SQL Se ...

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.

Collapse -

Exec SQL String in SQL Serv. Stored Proc

by frankus In reply to Exec SQL String in SQL Se ...

Poster rated this answer

Collapse -

Exec SQL String in SQL Serv. Stored Proc

by frankus In reply to Exec SQL String in SQL Se ...

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums