1、T-SQL INSERT 子查询例子
INSERT into [dqdata].[dbo].[s_Query_GUI]
([报表序号]
)
select
报表序号
from
dbo.s_query
2、插入一行
INSERT INTO t_upsNode(
companyId, stateId, upsId, originalUpsName, isActivate, upsManufactId
, upsModelId, upsVersion, agentVersion, ip, PORT, mac, memo, capability
, configOutputPower, configInputVa, configOutputVolt, configInputFreq
, configOutputFreq, createTime, isMonitorService
)
VALUES (
1, 1, "no.01", "测试设备1", TRUE, 1
, (SELECT id upsModelId FROM t_upsModel WHERE CNName = "M9900"),"1.0"
, "1.0", "127.0.0.1", "8080", "123", "备注", 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
, "2018-01-10 10:00:00", TRUE
)
3、插入多行
INSERT INTO t_upsNode (companyId, stateId, upsId, originalUpsName, isActivate, upsManufactId
, upsModelId, upsVersion, agentVersion, ip, PORT, mac, memo, capability
, configOutputPower, configInputVa, configOutputVolt, configInputFreq
, configOutputFreq, createTime, isMonitorService)
VALUES
(1, 1, "no.01", "测试设备1", TRUE, 1
, (SELECT id upsModelId FROM t_upsModel WHERE CNName = "M9900"),"1.0"
, "1.0", "127.0.0.1", "8080", "123", "备注", 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
, "2018-01-10 10:00:00", TRUE),
(1, 1, "no.01", "测试设备1", TRUE, 1
, (SELECT id upsModelId FROM t_upsModel WHERE CNName = "M9900"),"1.0"
, "1.0", "127.0.0.1", "8080", "123", "备注", 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
, "2018-01-10 10:00:00", TRUE )
4、INSERT INTO … SELECT 插入子查询数据
INSERT INTO [dbo].[s_colors]
(
色组名称, 色号01, 色号02, 色号03, 色号04, 色号05, 色号06, 色号07, 色号08, 色号09, 色号10, 色号11, 色号12, 色号13, 色号14, 色号15, 色号16, 色号17, 色号18, 色号19, 色号20
)
SELECT
色组名称, 色号01, 色号02, 色号03, 色号04, 色号05, 色号06, 色号07, 色号08, 色号09, 色号10, 色号11, 色号12, 色号13, 色号14, 色号15, 色号16, 色号17, 色号18, 色号19, 色号20
FROM [dqbak2].[dbo].[s_colors]