Showing posts with label random. Show all posts
Showing posts with label random. Show all posts

Friday, March 23, 2012

insert value into 2 columns,1 col. should take data from another table & 2nd random

Hi,

I have table which has 2 columns
username
password

i want to insert username values from by copying data from another table whereas password shd be randomly generated

Thank You

Quote:

Originally Posted by parshupooja

Hi,

I have table which has 2 columns
username
password

i want to insert username values from by copying data from another table whereas password shd be randomly generated


Thank You



Are you looking at doing this directly in MySQL, or do you have a thin/fat client you would like to do this through? I don't believe there is a random text function in MySQL, but many programming languages have ways to accomplish it.|||i am working SQL Server 2005. yes need to do it directly

Quote:

Originally Posted by ilearneditonline

Are you looking at doing this directly in MySQL, or do you have a thin/fat client you would like to do this through? I don't believe there is a random text function in MySQL, but many programming languages have ways to accomplish it.

Wednesday, March 7, 2012

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. :confused: Anyone knows how to solve this...PLEASE?No need for replies guys..ive figured this out ..thanx, anyway :)|||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|||[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 :)