DevonEilers
DevonEilers

Reputation: 33

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).

How might I go about doing this?

Upvotes: 0

Views: 526

Answers (1)

SPFiredrake
SPFiredrake

Reputation: 3892

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

Upvotes: 2

Related Questions