Ir para conteúdo
Fórum Script Brasil
  • 0

Order Function Returned Table


shaq

Pergunta

Hi, here is the problem

/* Order Function Returned Table *
Need to minimaly change a function(GetBigTableData), 
so that it returns the same results but ordered.
PS: Working in SQL Server 2005
*/
/* Assuming that: BigTable, @ReturnTable e @AuxTable have the same schema */
create function GetBigTableData (@All bit=0)
returns @ReturnTable table(col int)
as
begin
declare @AuxTable Table(col int)
/*-----UNCHANGABLE CODE--------------------------------------*/
    insert into @AuxTable
        select * from BigTable where BigTable.col < 5
    if @All=1
    begin
        insert into @AuxTable
            select * from BigTable where BigTable.col >= 5
    end
/*----------------------------------------------------------*/            
    insert into @ReturnTable
        select * from @AuxTable
            order by @AuxTable.col        --Error: Must declare the scalar variable "@AuxTable".
            --order by @ReturnTable.col    --Error: Must declare the scalar variable "@ReturnTable".
    return
end
go

Any Solutions?

Many Thanks,

Rui Miranda

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Dear Shap,

Remove the variable reference order by @AuxTable.col by order by col.

/* Order Function Returned Table *
Need to minimaly change a function(GetBigTableData),
so that it returns the same results but ordered.
PS: Working in SQL Server 2005
*/
/* Assuming that: BigTable, @ReturnTable e @AuxTable have the same schema */
create function GetBigTableData (@All bit=0)
returns @ReturnTable table(col int)
as
begin
declare @AuxTable Table(col int)
/*-----UNCHANGABLE CODE--------------------------------------*/
    insert into @AuxTable
        select * from BigTable where BigTable.col < 5
    if @All=1
    begin
        insert into @AuxTable
            select * from BigTable where BigTable.col >= 5
    end
/*----------------------------------------------------------*/            
    insert into @ReturnTable
        select * from @AuxTable
            order by col        --Error: Must declare the scalar variable "@AuxTable".
            --order by @ReturnTable.col    --Error: Must declare the scalar variable "@ReturnTable".
    return
end
go

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...