Re: sorting variables in a stored procedure

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Derek Shi (shi.d_at_ghc.org)
Date: 01/06/05


Date: Thu, 6 Jan 2005 08:58:31 -0800

For example: I need to insert 5 parameters @p1, @p2, @p3,
@p4, @p5 into one row in a table NUMBER_TABLE, such as
follows:

NUMBER_TABLE
n1 n2 n3 n4 n5
-- -- -- -- --
7 12 45 67 78

I need the numbers to be sorted before insert because I
need to calculate some statistics for each n1, n2, ... n5.

However, when the procedure is called (supposing procedure
is AddNumber @p1 int, @p2 int, @p3 int, @p4 int, @p5 int
As ...), the user might enter like this:

  Exec AddNumber 12, 7, 45, 78, 67

I need to sort those five numbers from the smallest to the
largest before do the insertion. Hope it helps.

Thanks,

Derek

>-----Original Message-----
>Can you post some more information on this? How will you
know what order
>they were inserted in? Why does it matter if they were
passed in randomly?
>Can't you just order them when you select from the table?
>
>--
>Adam Machanic
>SQL Server MVP
>http://www.sqljunkies.com/weblog/amachanic
>--
>
>
>"Derek Shi" <shi.d@ghc.org> wrote in message
>news:0ac601c4f37d$357c59e0$a601280a@phx.gbl...
>> Hi,
>>
>> I have a stored procedure with 5 integer parameters
passed
>> in. Those 5 integers need to be stored in one table row
>> from the smallest one to the largest. But when the
>> procedure is used, the 5 integers will be randomly
passed
>> in. How can I sort them inside the procedure before
insert
>> them into a table row?
>>
>> Thanks,
>>
>> Derek
>
>
>.
>



Relevant Pages

  • RE: Checking if entry is already in List
    ... Below is an InsertItem subroutine, a fast Heap sort, and a binary search to ... Dim ExactMatch As Boolean ... Dim nent As Long ... ' find the insertion position but skip insertion if no dups allowed and ...
    (microsoft.public.vb.general.discussion)
  • Re: ORDER BY in VIEW not working
    ... Table - by definition, no sort order allowed. ... Stored Procedure - Testing shows that ... ... compromise to allow a stored procedure to return an ordered set, ... compromise whereby a view could also return an ordered set. ...
    (comp.databases.ms-sqlserver)
  • Re: Suggestions to control concurrent users...
    ... Another problem could be that an advanced user could create a stored procedure that deletes all the entries that are inserted in the db continuously (or triggered by an insertion) so he could bypass my user control scenario. ... The problem with "vanishing applications", can be solved by means of a stored procedure that each application has to execute at regular intervals to update it's "state", a watch dog running in SQL server could remove non updated entries at regular intervals. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Best way to insert sorted in a list
    ... One is, to append the new value, and then sort the list. ... interpolative search to find the proper insertion point. ... to use a red-black tree, an AVL tree, or a skip list. ...
    (comp.lang.python)
  • sorting (was Re: VERY URGENT C PROGRAM)
    ... The first point is true of bubble sort and ... less true of insertion sort (because we have to make room for the ... insertion in the array). ... deck of cards handy, pick out two cards and hold them in one hand. ...
    (comp.lang.c)