ascending numbers

  • Sean Lange (5/22/2012)


    I don't think t-sql is a good approach to solve for Keprekar series for mere mortals like myself. However, there are probably some ways to do this that are far more complicated than I would try to do with sql. I stand corrected, it can be done, even relatively quickly. If I had to write this I would still do it in a programming language. 😛

    Agreed. One of the reasons I don't submit for the T-SQL challenges is that they insist on using the wrong tool for job more often than not.

    Those solutions are extremely inventive.

    Yes they are. I had no idea they existed before reading this thread though.

  • CLR Time 😀

    Before we proceed, i am total newbie to CLR and C# and built this sitting this morning 😎

    without further ado, here is the C# code:

    using System;

    using System.Data;

    using System.Text;

    using System.Data.SqlClient;

    using System.Data.SqlTypes;

    using Microsoft.SqlServer.Server;

    public partial class UserDefinedFunctions

    {

    [Microsoft.SqlServer.Server.SqlFunction]

    public static SqlInt32 SortDigits(SqlInt32 Number)

    {

    String[] ArrayStore;

    StringBuilder sb = new StringBuilder();

    //Number = 7861282;

    string NumAsString = Number.ToString();

    ArrayStore = new String[NumAsString.Length];

    String cut = String.Empty;

    for (int i = 0; i < NumAsString.Length; i++)

    {

    cut = NumAsString.Substring(i,1);

    ArrayStore = cut;

    }

    Array.Sort(ArrayStore);

    foreach (String iteminArray in ArrayStore)

    {

    sb.Append(iteminArray.ToString());

    }

    cut = String.Empty;

    cut = sb.ToString();

    SqlString st = (SqlString)cut;

    SqlInt32 sint = (SqlInt32)st;

    return sint;

    }

    };

    Here is the ASSEMBLY creation:

    CREATE ASSEMBLY [SortDigits]

    AUTHORIZATION [dbo]

    FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300B921BC4F0000000000000000E00002210B010800000A000000060000000000007E280000002000000040000000004000002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000242800005700000000400000A003000000000000000000000000000000000000006000000C000000B42700001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E746578740000008408000000200000000A000000020000000000000000000000000000200000602E72737263000000A00300000040000000040000000C0000000000000000000000000000400000402E72656C6F6300000C0000000060000000020000001000000000000000000000000000004000004200000000000000000000000000000000602800000000000048000000020005001C21000098060000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013300300B50000000100001100730F00000A0B0F00FE16020000016F1000000A0C086F1100000A8D130000010A7E1200000A0D1613042B1700081104176F1300000A0D06110409A2001104175813041104086F1100000AFE04130911092DD906280100002B000006130A16130B2B1D110A110B9A1305000711056F1000000A6F1500000A2600110B1758130B110B110A8E69FE04130911092DD57E1200000A0D076F1000000A0D09281600000A13061106281700000A1307110713082B0011082A1E02281800000A2A00000042534A4201000100000000000C00000076322E302E35303732370000000005006C00000028020000237E000094020000F802000023537472696E6773000000008C050000080000002355530094050000100000002347554944000000A4050000F400000023426C6F620000000000000002000001471502000908000000FA2533001600000100000015000000020000000200000001000000180000000C0000000100000001000000020000000100000000000A0001000000000006003E0037000A00660051000600990087000600B00087000600CD0087000600EC00870006000501870006001E01870006003901870006005401870006008C016D010600A00187000600CC01B9013700E001000006000F02EF0106002F02EF010A0068024D02060089027D020600A00237000600C20237000A00D40251000000000001000000000001000100010010001900000005000100010050200000000096006F000A00010011210000000086187A001100020000000100800019007A00150021007A00150029007A00150031007A00150039007A00150041007A00150049007A00150051007A00150059007A001A0061007A00150069007A001F0079007A00250081007A00110089007A00110091007A001100090097022F009900A70233009900B20237009900B8023A00A100C80240009100CD024C00A900DE0252001100EA02580009007A001100200073002A002E002B0074002E00130084002E001B0084002E0023008A002E000B0074002E0033009C002E003B0084002E004B0084002E005B00C0002E006300C9002E006B00D2005F000480000001000000AD111C6D0000000000006F00000002000000000000000000000001002E00000000000200000000000000000000000100450000000000290048000000003C4D6F64756C653E00536F72744469676974732E646C6C0055736572446566696E656446756E6374696F6E73006D73636F726C69620053797374656D004F626A6563740053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C496E74333200536F7274446967697473002E63746F72004E756D6265720053797374656D2E5265666C656374696F6E00417373656D626C795469746C6541747472696275746500417373656D626C794465736372697074696F6E41747472696275746500417373656D626C79436F6E66696775726174696F6E41747472696275746500417373656D626C79436F6D70616E7941747472696275746500417373656D626C7950726F6475637441747472696275746500417373656D626C79436F7079726967687441747472696275746500417373656D626C7954726164656D61726B41747472696275746500417373656D626C7943756C747572654174747269627574650053797374656D2E52756E74696D652E496E7465726F70536572766963657300436F6D56697369626C6541747472696275746500417373656D626C7956657273696F6E4174747269627574650053797374656D2E446961676E6F73746963730044656275676761626C6541747472696275746500446562756767696E674D6F6465730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465004D6963726F736F66742E53716C5365727665722E5365727665720053716C46756E6374696F6E4174747269627574650053797374656D2E5465787400537472696E674275696C64657200546F537472696E6700537472696E67006765745F4C656E67746800456D70747900537562737472696E6700417272617900536F727400417070656E640053716C537472696E67006F705F496D706C69636974006F705F4578706C6963697400000000032000000000002026333A19E482429E107D62734AECA00008B77A5C561934E0890600011109110903200001042001010E0420010102052001011139042001010804010000000320000E0320000802060E0520020E080807100101011D1E00030A010E05200112490E05000111550E0600011109115514070C1D0E12490E0E080E115511091109021D0E080F01000A536F727444696769747300000501000000001101000C4D6963726F736F667420495400002301001E436F7079726967687420C2A9204D6963726F736F6674204954203230313200000801000701000000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F77730100000000000000B921BC4F000000000200000053000000D0270000D0090000525344539BFF3F293170024ABF392149E142404401000000453A5C446F744E65745C536F72744469676974735C53706C6974537472696E67735C6F626A5C44656275675C536F72744469676974732E70646200004C28000000000000000000006E280000002000000000000000000000000000000000000000000000602800000000000000000000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF2500204000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000440300000000000000000000440334000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000001001C6DAD11000001001C6DAD113F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B004A4020000010053007400720069006E006700460069006C00650049006E0066006F0000008002000001003000300030003000300034006200300000003C000D00010043006F006D00700061006E0079004E0061006D006500000000004D006900630072006F0073006F00660074002000490054000000000040000B000100460069006C0065004400650073006300720069007000740069006F006E000000000053006F00720074004400690067006900740073000000000040000F000100460069006C006500560065007200730069006F006E000000000031002E0030002E0034003500320035002E00320037003900330032000000000040000F00010049006E007400650072006E0061006C004E0061006D006500000053006F00720074004400690067006900740073002E0064006C006C000000000060001E0001004C006500670061006C0043006F007000790072006900670068007400000043006F0070007900720069006700680074002000A90020004D006900630072006F0073006F006600740020004900540020003200300031003200000048000F0001004F0072006900670069006E0061006C00460069006C0065006E0061006D006500000053006F00720074004400690067006900740073002E0064006C006C000000000038000B000100500072006F0064007500630074004E0061006D0065000000000053006F00720074004400690067006900740073000000000044000F000100500072006F006400750063007400560065007200730069006F006E00000031002E0030002E0034003500320035002E00320037003900330032000000000048000F00010041007300730065006D0062006C0079002000560065007200730069006F006E00000031002E0030002E0034003500320035002E00320037003900330032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000803800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

    WITH PERMISSION_SET = SAFE

    GO

    Here is the function

    CREATE FUNCTION dbo.SortDigits (@Numbers INT)

    RETURNS INT

    AS

    EXTERNAL NAME SortDigits.UserDefinedFunctions.SortDigits;

    The usage:

    SELECT n.n, dbo.SortDigits(N.N)

    FROM Tally N

    One problem i noticed with the C# code is that, any number that has a zero, the zero is disregarded by the code. I can work on the fix, but i dont have much time..

  • SQL Kiwi (5/22/2012)


    I would probably implement this in a SQLCLR scalar function, but this is another option for T-SQL:

    SELECT

    REPLICATE('0', LEN(f.string) - LEN(REPLACE(f.string, '0', ''))) +

    REPLICATE('1', LEN(f.string) - LEN(REPLACE(f.string, '1', ''))) +

    REPLICATE('2', LEN(f.string) - LEN(REPLACE(f.string, '2', ''))) +

    REPLICATE('3', LEN(f.string) - LEN(REPLACE(f.string, '3', ''))) +

    REPLICATE('4', LEN(f.string) - LEN(REPLACE(f.string, '4', ''))) +

    REPLICATE('5', LEN(f.string) - LEN(REPLACE(f.string, '5', ''))) +

    REPLICATE('6', LEN(f.string) - LEN(REPLACE(f.string, '6', ''))) +

    REPLICATE('7', LEN(f.string) - LEN(REPLACE(f.string, '7', ''))) +

    REPLICATE('8', LEN(f.string) - LEN(REPLACE(f.string, '8', ''))) +

    REPLICATE('9', LEN(f.string) - LEN(REPLACE(f.string, '9', '')))

    FROM #Number AS n

    OUTER APPLY

    (

    SELECT

    CONVERT(varchar(19),n.Num) COLLATE Latin1_General_BIN2

    ) AS f (string);

    Cool solution Paul! But could you offer an explanation of how it works?

    My brute force effort would have been:

    CREATE TABLE #N(Num BIGINT)

    INSERT INTO #N(Num)

    SELECT 2456 UNION ALL

    SELECT 12343 UNION ALL

    SELECT 445599995544 UNION ALL

    SELECT 34534526262625263

    ;WITH Tally (n) AS (SELECT TOP 100 ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM sys.all_columns),

    AddID (Num, ID) AS (SELECT CAST(Num AS VARCHAR(50)), ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM #N),

    Numbers AS (

    SELECT ID, Num, Num2, r=ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Num2)

    FROM AddID CROSS APPLY (SELECT SUBSTRING(Num, n, 1) FROM Tally WHERE n BETWEEN 1 AND LEN(Num)) x(Num2)),

    PutItTogether (Num, Num2) AS (

    SELECT Num, (SELECT Num2 FROM Numbers n2 WHERE n1.ID = n2.ID ORDER BY r

    FOR XML PATH(''), root('MyString'), type

    ).value('/MyString[1]','varchar(max)' )

    FROM Numbers n1)

    SELECT Num=CAST(Num AS BIGINT), Num2 = CAST(MAX(Num2) AS BIGINT)

    FROM PutItTogether

    GROUP BY Num

    ORDER BY Num2

    DROP TABLE #N

    But it is quite similar to some of the earlier postings.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (5/22/2012)


    Cool solution Paul! But could you offer an explanation of how it works?

    It works out how many of each digit are in the initial string, and forms the result by concatenating that many of each digit in the required order. Working out how many times a digit appears in the string is just the length of the string minus the same string with all occurrences of the desired character removed. The REPLICATE function and normal concatenation does the rest. The APPLY is just there to convert the input number to a varchar.

  • SQL Kiwi (5/22/2012)


    dwain.c (5/22/2012)


    Cool solution Paul! But could you offer an explanation of how it works?

    It works out how many of each digit are in the initial string, and forms the result by concatenating that many of each digit in the required order. Working out how many times a digit appears in the string is just the length of the string minus the same string with all occurrences of the desired character removed. The REPLICATE function and normal concatenation does the rest. The APPLY is just there to convert the input number to a varchar.

    But why the COLLATION?

    ColdCoffee brings up an interesting point - what to do with 0s? Clearly appearing at the beginning of the number they are removed when converting back to integers. Wondering if that is the rule.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (5/22/2012)


    But why the COLLATION?

    http://connect.microsoft.com/SQLServer/feedback/details/512459/replace-function-extremely-slow-with-non-binary-windows-collation

    ColdCoffee brings up an interesting point - what to do with 0s? Clearly appearing at the beginning of the number they are removed when converting back to integers. Wondering if that is the rule.

    Dunno. To be honest with you, I'm a bit busy with something else right now. If I have time later, I'll look.

  • Perhaps one day I'll be smart enough to report a SQL bug to Microsoft and have them acknowlege it as such. I'll need to remember this one.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • ColdCoffee (5/22/2012)


    using System;

    using System.Data;

    using System.Text;

    using System.Data.SqlClient;

    using System.Data.SqlTypes;

    using Microsoft.SqlServer.Server;

    public partial class UserDefinedFunctions

    {

    [Microsoft.SqlServer.Server.SqlFunction]

    public static SqlInt32 SortDigits(SqlInt32 Number)

    {

    String[] ArrayStore;

    StringBuilder sb = new StringBuilder();

    //Number = 7861282;

    string NumAsString = Number.ToString();

    ArrayStore = new String[NumAsString.Length];

    String cut = String.Empty;

    for (int i = 0; i < NumAsString.Length; i++)

    {

    cut = NumAsString.Substring(i,1);

    ArrayStore = cut;

    }

    Array.Sort(ArrayStore);

    foreach (String iteminArray in ArrayStore)

    {

    sb.Append(iteminArray.ToString());

    }

    cut = String.Empty;

    cut = sb.ToString();

    SqlString st = (SqlString)cut;

    SqlInt32 sint = (SqlInt32)st;

    return sint;

    }

    };One problem i noticed with the C# code is that, any number that has a zero, the zero is disregarded by the code. I can work on the fix, but i dont have much time..

    The reason the 0 is disregarded is that you're returning an INT so the 0 is dropped because 01234 is not a valid INT.

    As for your CLR, no need for all your string builders. Try this: -

    using System;

    using System.Data.SqlTypes;

    namespace SortString

    {

    public class UserDefinedFunctions

    {

    [Microsoft.SqlServer.Server.SqlFunction]

    public static SqlString UDF_SortString(SqlInt64 number)

    {

    string returnString;

    try

    {

    var arr = number.ToString().ToCharArray(0, number.ToString().Length);

    Array.Sort(arr);

    returnString = new string(arr);

    }

    catch (Exception)

    {

    returnString = "";

    }

    return new SqlString((string) (returnString == "" ? SqlString.Null : returnString));

    }

    };

    }

    CREATE FUNCTION [dbo].[UDF_SortString](@number [bigint])

    RETURNS [nvarchar](4000) WITH EXECUTE AS CALLER

    AS

    EXTERNAL NAME [SortString].[SortString.UserDefinedFunctions].[UDF_SortString]

    GO

    CREATE ASSEMBLY [SortString]

    AUTHORIZATION [dbo]

    FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300BF97BC4F0000000000000000E00002210B010800000A000000060000000000004E280000002000000040000000004000002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000FC2700004F000000004000004803000000000000000000000000000000000000006000000C000000602700001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E746578740000005408000000200000000A000000020000000000000000000000000000200000602E72737263000000480300000040000000040000000C0000000000000000000000000000400000402E72656C6F6300000C000000006000000002000000100000000000000000000000000000400000420000000000000000000000000000000030280000000000004800000002000500E42000007C06000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001B3003006E0000000100001100000F00FE16030000016F0F00000A160F00FE16030000016F0F00000A6F1000000A6F1100000A0B07280100002B0007731300000A0A00DE0B260072010000700A00DE0000067201000070281400000A2D0806281500000A2B057E1600000A281700000A731800000A0C2B00082A000001100000000001003839000B150000011E02281900000A2A42534A4201000100000000000C00000076322E302E35303732370000000005006C00000030020000237E00009C020000FC02000023537472696E6773000000009805000004000000235553009C050000100000002347554944000000AC050000D000000023426C6F620000000000000002000001471502000908000000FA2533001600000100000015000000020000000200000001000000190000000C0000000100000001000000020000000100000000000A000100000000000600490042000A0071005C000A007B005C000600B200A0000600C900A0000600E600A00006000501A00006001E01A00006003701A00006005201A00006006D01A0000600A50186010600B901A0000600E501D2013B00F90100000600280208020600480208020A008102660206009F0242000600BD0242000600F102420000000000010000000000010001000100100019002E00050001000100502000000000960084000A000100DC20000000008618930011000200000001009900210093001500290093001500310093001500390093001500410093001500490093001500510093001500590093001500610093001A00690093001500710093001F00810093002500890093001100910093001100090096022F009900A60233009900B1023700A100C3023E00990093004A009900C80250001100D40256001100E0025C001100E5026000110093001500090093001100200073002A002E002B006E002E0013007E002E001B007E002E0023007E002E000B006E002E00330084002E003B007E002E004B007E002E005B009C002E006300A5002E006B00AE0066000480000001000000AE119F370000000000002E000000020000000000000000000000010039000000000002000000000000000000000001005000000000002500460000000000003C4D6F64756C653E00536F7274537472696E672E646C6C0055736572446566696E656446756E6374696F6E7300536F7274537472696E67006D73636F726C69620053797374656D004F626A6563740053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C537472696E670053716C496E743634005544465F536F7274537472696E67002E63746F72006E756D6265720053797374656D2E5265666C656374696F6E00417373656D626C795469746C6541747472696275746500417373656D626C794465736372697074696F6E41747472696275746500417373656D626C79436F6E66696775726174696F6E41747472696275746500417373656D626C79436F6D70616E7941747472696275746500417373656D626C7950726F6475637441747472696275746500417373656D626C79436F7079726967687441747472696275746500417373656D626C7954726164656D61726B41747472696275746500417373656D626C7943756C747572654174747269627574650053797374656D2E52756E74696D652E496E7465726F70536572766963657300436F6D56697369626C6541747472696275746500417373656D626C7956657273696F6E4174747269627574650053797374656D2E446961676E6F73746963730044656275676761626C6541747472696275746500446562756767696E674D6F6465730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465004D6963726F736F66742E53716C5365727665722E5365727665720053716C46756E6374696F6E41747472696275746500546F537472696E6700537472696E67006765745F4C656E67746800546F43686172417272617900417272617900536F7274006F705F457175616C697479006F705F496D706C69636974004E756C6C006F705F4578706C6963697400457863657074696F6E0000000100001DBCDC361BE3B243BF1DCBB86E8B43010008B77A5C561934E0890600011109110D03200001042001010E042001010205200101113D042001010804010000000320000E032000080620021D03080807100101011D1E00030A0103052001011D03050002020E0E05000111090E030611090500010E11090707030E1D0311090F01000A536F7274537472696E67000005010000000017010012436F7079726967687420C2A920203230313200000801000701000000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F77730100000000000000BF97BC4F00000000020000007D0000007C2700007C09000052534453F112B540E1E6244CA153D7BE98FC44CD04000000633A5C75736572735C6372616967775C646F63756D656E74735C76697375616C2073747564696F20323031305C50726F6A656374735C536F7274537472696E675C536F7274537472696E675C6F626A5C44656275675C536F7274537472696E672E706462000000002428000000000000000000003E28000000200000000000000000000000000000000000000000000030280000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF2500204000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000F00200000000000000000000F00234000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000001009F37AE11000001009F37AE113F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B00450020000010053007400720069006E006700460069006C00650049006E0066006F0000002C020000010030003000300030003000340062003000000040000B000100460069006C0065004400650073006300720069007000740069006F006E000000000053006F007200740053007400720069006E0067000000000040000F000100460069006C006500560065007200730069006F006E000000000031002E0030002E0034003500320036002E00310034003200330039000000000040000F00010049006E007400650072006E0061006C004E0061006D006500000053006F007200740053007400720069006E0067002E0064006C006C00000000004800120001004C006500670061006C0043006F007000790072006900670068007400000043006F0070007900720069006700680074002000A900200020003200300031003200000048000F0001004F0072006900670069006E0061006C00460069006C0065006E0061006D006500000053006F007200740053007400720069006E0067002E0064006C006C000000000038000B000100500072006F0064007500630074004E0061006D0065000000000053006F007200740053007400720069006E0067000000000044000F000100500072006F006400750063007400560065007200730069006F006E00000031002E0030002E0034003500320036002E00310034003200330039000000000048000F00010041007300730065006D0062006C0079002000560065007200730069006F006E00000031002E0030002E0034003500320036002E00310034003200330039000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000503800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

    WITH PERMISSION_SET = SAFE

    CREATE TABLE #Number(Num BIGINT);

    INSERT INTO #Number(Num)

    SELECT 2456 UNION ALL

    SELECT 12343 UNION ALL

    SELECT 445599995544 UNION ALL

    SELECT 34534526262625263 UNION ALL

    SELECT 345345260262625263;

    SELECT Num, dbo.UDF_SortString(Num)

    FROM #Number;


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 8 posts - 16 through 22 (of 22 total)

You must be logged in to reply to this topic. Login to reply