What is DYNAMIC SQL method ?

Questions by Beena   answers by Beena

Showing Answers 1 - 2 of 2 Answers

In dynamic SQL method 4 in  queries(select ) there are variable number of column and bind variable . Other word we can say that until run time we don't how many bind varible there.

  Exemple :-

   select :select_list Column from tablename where :wherecluase

If any query don't hesitate write on rahultripath@myway.com

  Was this answer useful?  Yes


  • Jun 1st, 2007

If we are speaking about SQL Server and Dynamic SQL, then the following is the answer.
Some queries in SQL Server might be given during run-time as we may not know the table that we might use in the procedure or batch. And so we do a dynamic SQL Statement.

@tblname varchar(80)            ----Input is table name

DECLARE @Qry Varchar(32)

SET @Qry = 'Select * from ' + @tblname
EXEC (@Qry)

Compile and run the above stored procedure and then run the following execute statement.

EXEC Some_sp 'Employees'

This is a very simple dynamic SQL. You can make it more complex and they have few restrictions that you need to keep intact.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions