我有两个SQL Server表,我想将数据从一个插入另一个。
我只希望将表A中的两列插入表B(其中包含两列以上)。我想在表B的其余部分添加一堆final Connection oc = find( (Connection) ( method.invoke( con, new Object[] { } ) ) );
if ( oc != null ) {
return oc;
}
s和1。
我看到this answer有帮助,但如果我愿意,例如:
null
' B' +地址正在抛出错误
转换varchar值时转换失败' B'到数据类型int
答案 0 :(得分:0)
试试这个:
INSERT INTO B (name, address, foo, bar, blah)
SELECT name, 'B'+ cast(address as varchar(250)), 1, 1, NULL
FROM table A
'或
; with CTE
as
(
SELECT NAME, 'B'+ cast(address as varchar(250)) [address], 1 AS FOO, 1 AS BAR, NULL AS BLAH
FROM TABLE A
)
INSERT INTO B (NAME,[ADRESS], FOO, BAR, BLAH)
SELECT NAME, [ADRESS], FOO, BAR, BLAH
FROM CTE