Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在SQL Server 2008的SQL查询中使用循环插入_Sql Server_Sql - Fatal编程技术网

Sql server 在SQL Server 2008的SQL查询中使用循环插入

Sql server 在SQL Server 2008的SQL查询中使用循环插入,sql-server,sql,Sql Server,Sql,从[点SEBAGOTHISTICKTCOMDB].[dbo].[tb\U席位] 其中[sectionID]=1和[RowId]='C' --对于此的每个id /****** Script for SelectTopNRows command from SSMS ******/ SELECT [Id] AS [SeatId] -- ignore seatId from the oringal table- it's not the true id, it's like a title 插入

从[点SEBAGOTHISTICKTCOMDB].[dbo].[tb\U席位] 其中[sectionID]=1和[RowId]='C'

--对于此的每个id

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT [Id] AS [SeatId]
  -- ignore seatId from the oringal table- it's not the true id, it's like a title
插入到[pointsebagothisticktcomdb].[dbo].[tb\u票证]
([showTimeId]
,[SeatId]
,[价格]
--,[notes]忽略[notes]我计划今天将其从模式中删除
,[保留时间]
,[标识符]
,[CreatedOn]
,[CreatedBy]
,[ModifiedOn]
,[经修改]
,[删除]
,[IsSold])
价值观
(-@showTimeId)
,--这是别名SeatId(实际上是[dbo].[tb_Seat].Id)
价格
--,忽略[NOTES]我计划今天将其从模式中删除
,--@reservedTime
,--由数据库自动指定为NEWGUID
,--自动分配=当前UTC日期时间
,--SET=@CreatedBy
,--自动分配=当前UTC日期时间
,--SET=@CreatedBy
,--SET=0
,)--SET=0
去
从第一个查询中,我得到了行数,比如说二十行,现在我想根据该行插入
如何根据它循环所有记录?

不要使用所有大写字母-看起来你在大喊大叫
INSERT INTO [pointsebagothisticketcomdb].[dbo].[tb_Ticket]
           ([showTimeId]
           ,[SeatId]
           ,[Price]
           -- ,[notes] IGNORE [NOTES] I PLAN TO REMOVE IT FROM SCHEMA TODAY
           ,[reservedTime]
           ,[Identifier]
           ,[CreatedOn]
           ,[CreatedBy]
           ,[ModifiedOn]
           ,[ModifiedBy]
           ,[IsDeleted]
           ,[IsSold])
     VALUES
           (<showTimeId, int,> -- @showTimeId
           ,<SeatId, int,> -- THIS IS THE alias SeatId (really [dbo].[tb_Seat].Id)
           ,<Price, decimal(10,2),> -- @price
           --,<notes, ntext,> IGNORE [NOTES] I PLAN TO REMOVE IT FROM SCHEMA TODAY
           ,<reservedTime, datetime,>  -- @reservedTime
           ,<Identifier, uniqueidentifier,> -- AUTOMATICALLY ASSIGNED BY THE DB AS NEWGUID
           ,<CreatedOn, datetime,> --  AUTOMATICALLY ASSIGNED = CURRENT UTC DATE TIME
           ,<CreatedBy, nvarchar(50),>  -- SET = @CreatedBy  
           ,<ModifiedOn, datetime,>  -- AUTOMATICALLY ASSIGNED = CURRENT UTC DATE TIME
           ,<ModifiedBy, nvarchar(50),>  -- SET = @CreatedBy  
           ,<IsDeleted, bit,>  -- SET = 0
           ,<IsSold, bit,>)  -- SET = 0
GO
INSERT INTO [pointsebagothisticketcomdb].[dbo].[tb_Ticket]
       ([SeatId]) 
SELECT [Id] AS [SeatId]
  FROM [pointsebagothisticketcomdb].[dbo].[tb_Seat]
  where [sectionID]  = 1 AND [RowId] = 'C'`