SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Generate MAc addresses with a stored procedure


Generate MAc addresses with a stored procedure

Author
Message
t.denys
t.denys
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 7
Hi all.

I would like to generate MAC addresses between a certain range in a stored procedure. The MAC addresses needed to be stored in a table.

Any ideas? Suggestions?

Thanks in advance :-D

Tom Denys
Matt Whitfield
Matt Whitfield
SSC Eights!
SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)

Group: General Forum Members
Points: 891 Visits: 719
Write a scalar UDF that returns you a MAC address based on an int, then use a commonly documented tally table method to generate the MAC addresses based on your selected range... I don't know the format of MAC addresses particularly, so sorry to not be more helpful...

Atlantis Interactive - SQL Server Tools
My blog
Why I wrote a sql query analyzer clone
t.denys
t.denys
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 7
Thanks for your answer but could you give me some sample code.

Regards
Tom
t.denys
t.denys
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 7
Thanks for your answer but is it possible to give me some sample code.

Regards
Tom
Matt Whitfield
Matt Whitfield
SSC Eights!
SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)

Group: General Forum Members
Points: 891 Visits: 719
Heh

http://lmgtfy.com/?q=sample+tally+table+t-sql

and

http://lmgtfy.com/?q=create+scalar+function+t-sql

Sorry - i'm more of a 'give a man a fishing rod' kind of guy :-D

Atlantis Interactive - SQL Server Tools
My blog
Why I wrote a sql query analyzer clone
Garadin
Garadin
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2799 Visits: 4107
Beyond which, I personally don't know the exact schema / rules for MAC addresses. Maybe I'm the only one. I'm sure I could google it and find it after a bit of research... but it'd be easier if I didn't have to.

Seth Phelabaum
Consistency is only a virtue if you're not a screwup. ;-)

Links: How to Post Sample Data :: Running Totals :: Tally Table :: Cross Tabs/Pivots :: String Concatenation
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28570 Visits: 39977
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!

t.denys
t.denys
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 7
Thank you but i need something like below


DECLARE @Max_MAC BINARY(8)
DECLARE @StartRange BINARY(8)
DECLARE @EndRange BINARY(8)
DECLARE @MAC_Address BINARY(8)

SET @StartRange = 0x00000004A500114B
SET @EndRange = 0x00000004A50F11FF

SELECT @Max_MAC = MAX(MAC_Address)
FROM MAC_Address

IF (@Max_Mac >= @StartRange and @Max_Mac < @EndRange)
begin

@Max_Mac = generate a higher macaddress
INSERT INTO MAC_Address(MAC_Address,Timestamp) VALUES (@MAX_MAC, getdate())
END


I do not know how I can count a number more to the MAcAdress I would like to become to a table with macadresses like

0x00000004A500114B
0x00000004A500114C
0x00000004A500114D
...
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28570 Visits: 39977
so you need to generate just under a million rows;
here's how i did it:

DECLARE @StartRange BINARY(8)
DECLARE @EndRange BINARY(8)
SET @StartRange = 0x00000004A500114B
SET @EndRange = 0x00000004A50F11FF

--select convert(integer,+ @EndRange) - convert(integer,+ @StartRange) = 983220

select convert(BINARY(8),RW + convert(integer, @StartRange))
from
(select row_number() over(order by a.id) As RW from syscolumns,syscolumns a,syscolumns b ,syscolumns c) b
where RW between 1 and (convert(integer, @EndRange) - convert(integer, @StartRange))




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!

Matt Miller (4)
Matt Miller (4)
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12509 Visits: 18582
Use the database as it should be. Generate ALL of the MAC addresses in one shot, and assign them as needed.

From what you have listed there - looks like you have 3 variable octets. This is simply an incrementing number represented in Hexadecimal format, so you should use the code provided to you for a Tally or Numbers table. Looks like your range is just shy of 1M numbers.

In addition - there are several Decimal to Hex utilities in the scripts area to implement. Having a decimal and hex notation column in your tally table, so that you can then simply append to the "fixed" octets.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search