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 2005 Forums
 Transact-SQL (2005)
 Order Function Returned Table

Author  Topic 

RMiranda
Starting Member

2 Posts

Posted - 2011-11-24 : 16:54:04
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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-24 : 20:30:35
just simply
order by col


Just curious, what is the purpose of having this function in the first place ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -