简体   繁体   English

将sql查询中的值与其他数据一起插入表列

[英]Inserting values from sql query into a table column along with other data

I have just created this table: 我刚刚创建了这个表:

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
)

What I am trying to do is populate the Name field with results from this query: 我想要做的是使用此查询的结果填充名称字段:

select distinct ordertype from unit_results

as well as inserting CreatedBy and ModifiedBy by hand (they will be the same for every row). 以及手动插入CreatedBy和ModifiedBy(它们对于每一行都是相同的)。

How might I go about doing this? 我该怎么做呢?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM