Friends,
I have this Function:
createCREATE functionFUNCTION [dbo].[fn_xxx]
(
@Nome varcharVARCHAR(100),
@Descricao varcharVARCHAR(500)
)
RETURNS @tbDados tableTABLE
(
Qtd intINT
)
as
BeginAS
BEGIN
declareDECLARE @CMD asAS nvarcharNVARCHAR(maxMAX)
;
declareDECLARE @Tabela varcharVARCHAR(100);
declareDECLARE @CampoDescricao varcharVARCHAR(100);
--- *** Identifica os campos e tabelas
setSET @Tabela = 'tbl' + @Nome@Nome;
setSET @CampoDescricao = 'Desc' + @Nome @Nome;
setSET @CMD = '
insertINSERT intoINTO @tbDados (Qtd) values
select SELECT @Qtd = COUNT(*) from
FROM ' + @Tabela + ' where
WHERE ' + @CampoDescricao + ' = ''' + replace(@Descricao, '''', '`') + ''''
''';';
execEXEC sp_executesql @CMD@CMD;
returnRETURN
endEND
I'm trying to help developers here, but with no success.
When we execute it ( select dbo.fn_xxx ('processador','teste')
) it give us this error:
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fn_xxx", or the name is ambiguous.
I've been searching through the internet, and found some results, but it was all about the code.
can someone help me how to figure out this error in this function?
Thanks
EDIT:
If i execute it with:
SELECT * FROM [EasyTablet].[dbo].[fn_xxx] (
'processador','teste'
)
GO
It shows me this error:
Only functions and some extended stored procedures can be executed from within a function.