将来自多个 table 的数据插入单个 table
Insert Data from multiple tables into a single table
INSERT INTO MonthlyFee(StudentID, ClassTypeID, Fee, MonthID,
[Year], IsDefaulter, FeeStatus, CreatedDate)
SELECT StudentID, ClassTypeID FROM ClassRollNo
我想设置以下值(主要是硬编码参数):MonthID 1、Year 2015、IsDefaulter FALSE、FeeStatus 0 和 CreatedDate GETDATE()。
只需按照插入 column list
的顺序在相同的 select
语句中硬编码这些值。试试这个语法
INSERT INTO MonthlyFee
(StudentID,
ClassTypeID,
Fee,
MonthID,
[Year],
IsDefaulter,
FeeStatus,
CreatedDate)
SELECT StudentID,
ClassTypeID,
100, -- You missed
1,
2015,
'false',
0,
Getdate()
FROM ClassRollNo
注意:你错过了我硬编码的费用栏
使用相同的查询和您描述的值:
INSERT INTO MonthlyFee(StudentID, ClassTypeID,Fee,MonthID,
[Year],IsDefaulter,FeeStatus,CreatedDate)
SELECT StudentID, ClassTypeID, 0, 1, 2015, 0, 0, GETDATE() FROM ClassRollNo
试试这个:
INSERT INTO MonthlyFee(StudentID, ClassTypeID,MonthID,
[Year],IsDefaulter,FeeStatus,CreatedDate)
SELECT StudentID, ClassTypeID,1,2013,false,0,getdate() FROM ClassRollNo
INSERT INTO MonthlyFee(StudentID, ClassTypeID, Fee, MonthID,
[Year], IsDefaulter, FeeStatus, CreatedDate)
SELECT StudentID, ClassTypeID FROM ClassRollNo
我想设置以下值(主要是硬编码参数):MonthID 1、Year 2015、IsDefaulter FALSE、FeeStatus 0 和 CreatedDate GETDATE()。
只需按照插入 column list
的顺序在相同的 select
语句中硬编码这些值。试试这个语法
INSERT INTO MonthlyFee
(StudentID,
ClassTypeID,
Fee,
MonthID,
[Year],
IsDefaulter,
FeeStatus,
CreatedDate)
SELECT StudentID,
ClassTypeID,
100, -- You missed
1,
2015,
'false',
0,
Getdate()
FROM ClassRollNo
注意:你错过了我硬编码的费用栏
使用相同的查询和您描述的值:
INSERT INTO MonthlyFee(StudentID, ClassTypeID,Fee,MonthID,
[Year],IsDefaulter,FeeStatus,CreatedDate)
SELECT StudentID, ClassTypeID, 0, 1, 2015, 0, 0, GETDATE() FROM ClassRollNo
试试这个:
INSERT INTO MonthlyFee(StudentID, ClassTypeID,MonthID,
[Year],IsDefaulter,FeeStatus,CreatedDate)
SELECT StudentID, ClassTypeID,1,2013,false,0,getdate() FROM ClassRollNo