sql server - How to use INSERT SELECT? -
i have table's structure:
[subjects]
:
- id int identity specification yes
- deleted bit
[juridical]
:
- id int
- name varchar
- typeid int
[individual]
:
- id int
- name varchar
juridical
, individual
it's children classes of subjects
class. it's mean same rows in tables individual
, subjects
have same id
.
now have table:
[mytable]
:
- typeid varchar
- name varchar
and want select data table , insert table structure. don't know do. tried use output
:
insert [individual](name) output false [subjects].[deleted] select [mytable].[name] name [mytable] [mytable].[type] = 'indv'
but syntax not correct.
just use:
insert individual(name) select [mytable].[name] name [mytable] [mytable].[type] = 'indv'
and
insert subjects(deleted) select [mytable].[name] name [mytable] [mytable].[type] = 'indv'
you can't insert in single query in 2 tables, need 2 separate queries that. reason split initial query 2 insert statements, add records both individual
, subjects
table.
just @marc_s said, must select exact number of columns in select
statement number of columns want insert data tables.
other these 2 constraints, both related syntax, allowed filtering in select
part or make complex logic in normal select
query.
Comments
Post a Comment