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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Function Syntaxt Error

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 VARCHAR
AS
BEGIN
DECLARE @sqlQuery VARCHAR(2500)
DECLARE @Output VARCHAR(2500)
SET @sqlQuery = ' SELECT '+@DisplayCol+' FROM '+@TName+' WHERE TransactionNo IN ('+Quotename(@TrnNo,'''')+')'
SET @Output=Exec(@sqlQuery)
RETURN @Output
END

The 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 process
regards
bhagwan"

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.

HTH


Dennis
Go to Top of Page
   

- Advertisement -