2012-07-05 54 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