SQL Server Insert Loop

hey folks,
  I want to do a "loop" to insert records.  One of the fields needs to be fr_(x) on the insert.
See my code below and let me know how I can do the insert for  = 'fr_' (1 - 9)

declare @galleryType nVarchar(30), @galleryPlayID nVarchar(30),@galleryContent nvarchar(MAX)
set @galleryType = 'test'
set @galleryPlayID = 'fr_' + (1 to x)
set @galleryContent='Content'
select @galleryType as galleryType, @galleryContent as galleryContent


INSERT INTO tblResortGallery
   (galleryType,
    galleryPlayID
    galleryPlayID,
    galleryContent)
select
   @galleryType,
   @galleryPlayID,
   @galleryContent
Larry Bristersr. DeveloperAsked:
Who is Participating?
 
puranik_pConnect With a Mentor Commented:
tell me if this is what you want...
declare @galleryType nVarchar(30), @galleryPlayID nVarchar(30),@galleryContent nvarchar(MAX)
set @galleryType = 'test'
set @galleryContent='Content'
 
DECLARE @x int
SET @x = 1
 
WHILE @x <= 9 -- put number of rows to be inserted here
BEGIN
SET @galleryPlayID =  'fr_' + convert(varchar(10),@x)
INSERT INTO tblResortGallery
   (galleryType,
    galleryPlayID,
    galleryContent)
select
   @galleryType,
   @galleryPlayID,
   @galleryContent
SET @x = @x + 1
END

Open in new window

0
 
Larry Bristersr. DeveloperAuthor Commented:
Perfect
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.