Home Forums SQL Server 7,2000 T-SQL Generate MAc addresses with a stored procedure RE: Generate MAc addresses with a stored procedure

  • ok here's one way:

    i'm assuming you want it in the same format i see when i do ipconfig/all

    pairs of [0-9,A-E] with dashes:

    cross joining the widget below against a row-number derived table gives me 100 examples as results...easily adjustable to your needs.

    00-1A-A0-CA-1E-51

    example results:

    92-1B-2B-9E-BC-42

    BD-28-61-DE-59-A2

    E5-65-A8-05-8D-82

    46-7B-5A-96-A0-EB

    from ipconfig/all:

    --Physical Address. . . . . . . . . : 00-1A-A0-CA-1E-51

    select

    Random_String =

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    '-' +

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    '-' +

    /* and so on for as many characters as needed */

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    '-' +

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    '-' +

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    '-' +

    substring(x,(abs(checksum(newid()))%15)+1,1)+

    substring(x,(abs(checksum(newid()))%15)+1,1)

    from

    (select x='0123456789ABCDE') a

    cross apply (select top 100 row_number() over(order by id) As RW from syscolumns) b

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!