If you need to insert random numbers mixed with strings into your table in SQL Server insert them one by one with few records, it’s ok. But if you need to insert many records, unique, and not duplicate numbers, it may be difficult for you.
But don’t worry the SQL Server can do it, you want to random numbers with strings and INSERT INTO a table 1000 or more recordings within a loop function. So you can do it with me step by step at the following :
Loop Function in SQL
The first time, please create a loop function. For example, loop 1000 records
DECLARE @i int = 0
WHILE @i < 1000
BEGIN
SET @i = @i + 1
/* your code */
END
How to Random number with string with StoredProcedure
Create StoredProcedure for random numbers with strings together
Create proc [dbo].[RandomChars]
@len int,
@min tinyint = 48,
@range tinyint = 74,
@exclude varchar(50) = '0:;<=>?@O[]`^\/._',
@output varchar(50) output
as
declare @char char
set @output = ''
while @len > 0 begin
select @char = char(round(rand() * @range + @min, 0))
if charindex(@char, @exclude) = 0 begin
set @output += @char
set @len = @len - 1
end
end
How to Call StoredProcedure
Call StoredProcedure and display random code in a list. For example, I need the length of the code to be 8
declare @newcode varchar(20)
exec [dbo].RandomChars @len=8, @output=@newcode out
Select (@newcode)
How to Insert Into a table
So you can mix code together of Loop function and random stored procedure :
DECLARE @i int = 0
WHILE @i < 1000
BEGIN
SET @i = @i + 1
declare @newcode varchar(20)
exec [dbo].RandomChars @len=8, @output=@newcode out
Insert into CODE_LISTS(CODE) VALUES(UPPER(@newpwd))
END
Final Result :
Copy the above code and run it on SQL Server, and you will get the result.
Great content! Keep up the good work!
Thanks
Useful information
Thanks 71a1da8
Thanks
Hello. I could help you to solve the problems with your site. I can make it more visited and more profitable. Attracting more visitors and conversion enhancement are my strong points. I have been engaged in site making, updating and promotion thereof since 2004, with both commercial and information projects. My rates are quite moderate.
I’m specializing in the following:
1. Website promotion in search engines. I could make it possible to bring your site to the top of the search results that are of interest to you.
2. Error correcting and site debugging. I will help make your site the highest quality and relevant to the requirements of search engines. I work on identifying and eliminating bugs, increasing conversions, speeding up site loading, etc. I deal with all kinds of issues, from code to design.
3. Site-making. I am engaged in the creation of sites of various types.
4. Start-up, content management and promotion of groups and channels in social networks (YouTube, Face book, etc.).
5. Customer feedback. Making and promoting good reviews on the Internet, removing and reducing the visibility of bad ones.
6. Various types of mailing lists selected from my databases for your business. I am engaged in the following mailings: e-mailing, feedback mailing, mailing by chats on websites, and on social network profiles.
7. There is much more that I could be of assistance to you with.
To contact me, please write to the following e-mail: itmikhailr85@gmail.com
You need to take part in a contest for one of the highest quality sites on the net. I am going to recommend this site!
Thanks
Hey there! Do you know if they make any plugins to safeguard against hackers?
I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions?
Hi, We use Google reCAPTCHA
Hey! I know this is somewhat off topic but I was wondering if you knew
where I could get a captcha plugin for my comment form?
I’m using the same blog platform as yours and I’m having difficulty finding one?
Thanks a lot!
Hi, We use Google reCAPTCHA
hey, thanks for sharing
You’re welcome!
좋은 게시물, 나는 그것을 내 친구들과 공유했습니다.
Posting yang bagus, saya telah membagikannya dengan teman-teman saya.
Thanks in favor of sharing such a good thinking, post
is fastidious, thats why i have read it entirely
Hmm is anyone else having problems with the images on this blog loading?
I’m trying to determine if its a problem on my end or if it’s the blog.
Any responses would be greatly appreciated.
Bel article, je l’ai partagé avec mes amis.
whoah this blog is fantastic i like reading your posts. Keep up the good work!
You already know, many people are hunting around for this information, you
can help them greatly.
Simply wish to say your article is as surprising. The clearness in your post is simply cool and i
can assume you’re an expert on this subject. Fine with your permission allow me to grab your RSS feed to
keep updated with forthcoming post. Thanks a million and
please continue the rewarding work.