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 |
|
shifis
Posting Yak Master
157 Posts |
Posted - 2008-03-11 : 18:48:40
|
| I have the next Function:CREATE FUNCTION F_StoreName( @strTienda as varchar(3) --Numero de Tienda)RETURNS VARCHAR(200)ASBEGINdeclare @strStoreName as varchar(30), @strSQLString nvarchar(500), @strParmDefinition nvarchar(500)--set @strTienda='003'SET @strSQLString = N'select @StoreName = max(nombre) ' + ' from ' + master.dbo.fGetServerName('bdSupport') + 'bdSupport..tbTiendas with (noLock) ' + ' where notienda= ' + @strTienda SET @strParmDefinition = N'@StoreName varchar(30) OUTPUT';--print @strSQLEXECUTE sp_executesql @strSQLString, @strParmDefinition, @StoreName=@strStoreName OUTPUT;RETURN @strStoreNameENDWhen I call this function:select dbo.F_StoreName('002') as xIt sent me next error:Only functions and extended stored procedures can be executed from within a function. |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-03-11 : 18:58:21
|
| You cannot use dynamic SQL (including sp_executesql) within a function.CODO ERGO SUM |
 |
|
|
|
|
|