Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-06-02 : 07:33:58
|
| Bhagwan writes "Hi,I have recently started working on sql server programming.My dynamic function is as under.Same gives syntax error when Iam trying to assign the dynamic sql value to a variable.CREATE FUNCTION BSMTest (@DisplayCol VARCHAR(30), @TrnNo INT, @TName VARCHAR(30))RETURNS VARCHARASBEGIN DECLARE @sqlQuery VARCHAR(2500) DECLARE @Output VARCHAR(2500) SET @sqlQuery = ' SELECT '+@DisplayCol+' FROM '+@TName+' WHERE TransactionNo IN ('+Quotename(@TrnNo,'''')+')' SET @Output=Exec(@sqlQuery) RETURN @OutputENDThe sql query which is built is select accountNo from vw_transactions_mortgages where TransactionNo in ('100004')It returns a single output.can someone help me out if Iam following a wrong processregardsbhagwan" |
|
|
dsdeming
479 Posts |
Posted - 2003-06-02 : 08:03:23
|
| The problem is, you can't use dynamic SQL in udfs. See CREATE FUNCTION in BOL for more details of what is and isn't allowed in udfs.HTHDennis |
 |
|
|
|
|
|