Skip to main content
improved formatting
Source Link
Hannah Vernon
  • 70.5k
  • 22
  • 177
  • 321

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.

Friends,

I have this Function:

create function [dbo].[fn_xxx]
    (
    @Nome varchar(100),
    @Descricao varchar(500)
    )
RETURNS @tbDados table
    (
        Qtd int
    )
as

Begin

    declare @CMD as nvarchar(max)
    
    declare @Tabela varchar(100)
    declare @CampoDescricao varchar(100)

    --- *** Identifica os campos e tabelas 
    set @Tabela = 'tbl' + @Nome 
    set @CampoDescricao = 'Desc' + @Nome    
    
    set @CMD = '
    insert into @tbDados (Qtd) values 
    select      @Qtd = COUNT(*) from ' + @Tabela + ' where ' + @CampoDescricao + ' = ''' + replace(@Descricao, '''', '`') + ''''



    
    exec sp_executesql @CMD
    
    return 
end 

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.

I have this Function:

CREATE FUNCTION [dbo].[fn_xxx]
    (
    @Nome VARCHAR(100),
    @Descricao VARCHAR(500)
    )
RETURNS @tbDados TABLE
    (
        Qtd INT
    )
AS
BEGIN
    DECLARE @CMD AS NVARCHAR(MAX);
    DECLARE @Tabela VARCHAR(100);
    DECLARE @CampoDescricao VARCHAR(100);

    --- *** Identifica os campos e tabelas 
    SET @Tabela = 'tbl' + @Nome; 
    SET @CampoDescricao = 'Desc' + @Nome;
    
    SET @CMD = '
    INSERT INTO @tbDados (Qtd) 
    SELECT @Qtd = COUNT(*) 
    FROM ' + @Tabela + ' 
    WHERE ' + @CampoDescricao + ' = ''' + replace(@Descricao, '''', '`') + ''';';

    EXEC sp_executesql @CMD;

    RETURN 
END 

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.

[Edit removed during grace period]
Link
Racer SQL
  • 7.5k
  • 14
  • 73
  • 136
added 262 characters in body
Source Link
Racer SQL
  • 7.5k
  • 14
  • 73
  • 136

Erro Error with FUNCTION ( SQL Server 2008 ) - ''Cannot find either column...'

Friends,

I have this Function:

create function [dbo].[fn_xxx]
    (
    @Nome varchar(100),
    @Descricao varchar(500)
    )
RETURNS @tbDados table
    (
        Qtd int
    )
as

Begin

    declare @CMD as nvarchar(max)
    
    declare @Tabela varchar(100)
    declare @CampoDescricao varchar(100)

    --- *** Identifica os campos e tabelas 
    set @Tabela = 'tbl' + @Nome 
    set @CampoDescricao = 'Desc' + @Nome    
    
    set @CMD = '
    insert into @tbDados (Qtd) values 
    select      @Qtd = COUNT(*) from ' + @Tabela + ' where ' + @CampoDescricao + ' = ''' + replace(@Descricao, '''', '`') + ''''



    
    exec sp_executesql @CMD
    
    return 
end 

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.

Erro with FUNCTION ( SQL Server 2008 )

Friends,

I have this Function:

create function [dbo].[fn_xxx]
    (
    @Nome varchar(100),
    @Descricao varchar(500)
    )
RETURNS @tbDados table
    (
        Qtd int
    )
as

Begin

    declare @CMD as nvarchar(max)
    
    declare @Tabela varchar(100)
    declare @CampoDescricao varchar(100)

    --- *** Identifica os campos e tabelas 
    set @Tabela = 'tbl' + @Nome 
    set @CampoDescricao = 'Desc' + @Nome    
    
    set @CMD = '
    insert into @tbDados (Qtd) values 
    select      @Qtd = COUNT(*) from ' + @Tabela + ' where ' + @CampoDescricao + ' = ''' + replace(@Descricao, '''', '`') + ''''



    
    exec sp_executesql @CMD
    
    return 
end 

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

Error with FUNCTION ( SQL Server 2008 ) - ''Cannot find either column...'

Friends,

I have this Function:

create function [dbo].[fn_xxx]
    (
    @Nome varchar(100),
    @Descricao varchar(500)
    )
RETURNS @tbDados table
    (
        Qtd int
    )
as

Begin

    declare @CMD as nvarchar(max)
    
    declare @Tabela varchar(100)
    declare @CampoDescricao varchar(100)

    --- *** Identifica os campos e tabelas 
    set @Tabela = 'tbl' + @Nome 
    set @CampoDescricao = 'Desc' + @Nome    
    
    set @CMD = '
    insert into @tbDados (Qtd) values 
    select      @Qtd = COUNT(*) from ' + @Tabela + ' where ' + @CampoDescricao + ' = ''' + replace(@Descricao, '''', '`') + ''''



    
    exec sp_executesql @CMD
    
    return 
end 

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.

Source Link
Racer SQL
  • 7.5k
  • 14
  • 73
  • 136
Loading