Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004
    Posts
    8

    Unanswered: insert random records..HELP!

    Once again - My table should consist of 100 new records for a field MobilePhone(of char type) and last 5 digits should be randomly choosed (should be like this: +381randomno1randomno2.. etc.(example: +38156465, where '+' sign makes it char type and digits after +381 are randomly choosed. Anyone knows how to solve this....PLEASE?
    Last edited by bejbika; 07-01-04 at 05:30.

  2. #2
    Join Date
    Jun 2004
    Posts
    8

    I got it

    No need for replies guys..ive figured this out ..thanx, anyway

  3. #3
    Join Date
    Feb 2004
    Posts
    134
    Quote Originally Posted by bejbika
    No need for replies guys..ive figured this out ..thanx, anyway
    Would it not be a good idea to post your solution? Some may benifit from your solution who may have a similar problem. Also, let's not forget the intelligence level in this community (excluding me of course); they may have suggestions to fine tune your solution!

    Just my oppinion. Every question posted should be accompanied by a solution I think!

    Mike B

  4. #4
    Join Date
    Jun 2004
    Posts
    8

    Thumbs up

    [QUOTE=MikeB_2k4]Would it not be a good idea to post your solution? Some may benifit from your solution who may have a similar problem. Also, let's not forget the intelligence level in this community (excluding me of course); they may have suggestions to fine tune your solution!

    Just my oppinion. Every question posted should be accompanied by a solution I think!



    Im really sorry..you are so right.Ok,here is the solution:



    create table #randomphonenumbers( nmbr char(10) primary key )

    declare @digits table(nr char(1))
    insert @digits(nr) select '0' union select '2' union select '4' union select '6' union select '8'
    insert @digits(nr) select nr+1 from @digits -- implicit conversion

    insert #randomphonenumbers( nmbr )
    select top 100 '+' + '388' + a.nr+b.nr+c.nr+d.nr+e.nr
    from @digits a cross join @digits b cross join @digits c cross join @digits d cross join @digits e
    where e.nr > 0
    order by newid()

    select * from #randomphonenumbers

    drop table #randomphonenumbers



    Bye now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •