使用来自 table 的 ID 并插入辅助 table
Using IDs from table and insert into secondary table
目前我正在尝试编写一个 sql 语句,其中 select 来自一个 table 然后使用主键插入辅助 table。我很难弄清楚我会怎么做。这是我现在拥有的 select 和插入内容。第一个 select 将 return 多个结果。我需要每晚 运行,所以我需要让它动态化。
SELECT ParentTypeId FROM Config_OrderParentQueueType
INSERT INTO [dbo].[Config_OrderParentQueueTypeNotes]
([ParentTypeId]
,[NoteDate]
,[NoteText]
,[NoteSubmittedById])
VALUES
(This is the ID I need to insert from the select
,GETDATE()
,'Default Note'
,6)
我试图弄乱行数,但 ID 并不总是连续的。提前感谢任何有关我如何执行此操作的帮助。
使用insert .. select
:
INSERT INTO [dbo].[Config_OrderParentQueueTypeNotes]
([ParentTypeId]
,[NoteDate]
,[NoteText]
,[NoteSubmittedById])
SELECT ParentTypeId, getdate(), 'Default Note', 6
FROM Config_OrderParentQueueType
目前我正在尝试编写一个 sql 语句,其中 select 来自一个 table 然后使用主键插入辅助 table。我很难弄清楚我会怎么做。这是我现在拥有的 select 和插入内容。第一个 select 将 return 多个结果。我需要每晚 运行,所以我需要让它动态化。
SELECT ParentTypeId FROM Config_OrderParentQueueType
INSERT INTO [dbo].[Config_OrderParentQueueTypeNotes]
([ParentTypeId]
,[NoteDate]
,[NoteText]
,[NoteSubmittedById])
VALUES
(This is the ID I need to insert from the select
,GETDATE()
,'Default Note'
,6)
我试图弄乱行数,但 ID 并不总是连续的。提前感谢任何有关我如何执行此操作的帮助。
使用insert .. select
:
INSERT INTO [dbo].[Config_OrderParentQueueTypeNotes]
([ParentTypeId]
,[NoteDate]
,[NoteText]
,[NoteSubmittedById])
SELECT ParentTypeId, getdate(), 'Default Note', 6
FROM Config_OrderParentQueueType