|
Home > Archive > SQL server exams > October 2002 > Coco's Question of the Week #12
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Coco's Question of the Week #12
|
|
| cocolocopolo 2002-10-09, 2:16 am |
| RE: Dynamic SQL
What is Dynamic SQL? | |
| 2lazybutsmart 2002-10-09, 7:34 am |
| Dynamic SQL statements are not completley hard coded. This means that you can store values in parameters and create the SQL statements using those parameters. For example.
------------------------------------
DECLARE @TblName, @WHEREColumn, @WHEREColumnValue
SET @TblName = 'Customers'
SET @WHEREColumn = 'CustomerID'
SET @WHEREColumnValue = 1
EXEC ('SELECT * FROM' + @TblName + 'WHERE ' + @WHEREColumn + '= ' + @WHEREColumnValue)
-------------------------------------------
You could pass those variable values through stored procedures if you like. anywayz, that's the game, dynamic SQL means creating the statement on-the-fly using provided values. as you can see the table name, where criteria column and value have been supplied in variables.
cheers,
2lazybutsmart
Just shout out when stuck  | |
| cocolocopolo 2002-10-11, 1:20 am |
| Thanks dear 2lazybutsmart.
Besides stored procedure, can we use dynamic
variables in something like trigger, functions, views??? |
|
|
|
|