2012-07-05 52 views
0

我刚刚创建了这个表中的其他数据一起到表列:插入从SQL查询值与

create table dbo.OrderTypes 
(
ID smallint primary key identity, 
Name varchar(300) not null, 
CreatedOn datetime default getdate(), 
CreatedBy nvarchar(300) not null, 
ModifiedOn datetime default getdate(), 
ModifiedBy nvarchar(300) not null 
) 

我所试图做的是填充名称字段与此查询结果:

select distinct ordertype from unit_results 

以及手动插入CreatedBy和ModifiedBy(它们对于每一行都是相同的)。

我该如何去做这件事?

+0

我建议你默认CreatedBy和ModifiedBy列到类似system_user的东西。那么当创建一行时,您不必提供这些值。 – 2012-07-05 21:19:42

回答

2
INSERT INTO dbo.OrderTypes (Name, CreatedBy, ModifiedBy) 
SELECT DISTINCT ordertype, 'CreatedBy Value Here', 'ModifiedBy Value Here' 
FROM unit_results 
+0

完美谢谢! – DevonEilers 2012-07-05 20:14:22