表A的列 SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
表B的列 Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan
现在要把B里的数据导到A,A里很多列的数据就是自动赋值了,请问SQL语句该怎么写?比如RecordID 用newid()来赋。
谢谢!
6 个解决方案
#1
default(某个值) 默认值即可自动赋值。
如果是可变值的话,可以改变recordID 为计算列。
如果是可变值的话,可以改变recordID 为计算列。
#2
insert 表B(字段列表)
select 字段列表 from 表A
(你要自动赋值就直接col=计算公式之类的东西)
select 字段列表 from 表A
(你要自动赋值就直接col=计算公式之类的东西)
#3
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan
from dbo.Sheet2$
这样会提示列数不一样。多出来的列的该怎么处理?
我是新手,请详细指点。谢谢。
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan
from dbo.Sheet2$
这样会提示列数不一样。多出来的列的该怎么处理?
我是新手,请详细指点。谢谢。
#4
多出来的列,LZ需要给出一个值。
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'...
from dbo.Sheet2$
不过多出来的列,可以不写出,当然前提是这列可以为空值,或有默认值,示例如下:
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'
from dbo.Sheet2$
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'...
from dbo.Sheet2$
不过多出来的列,可以不写出,当然前提是这列可以为空值,或有默认值,示例如下:
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'
from dbo.Sheet2$
#5
借楼主代码举个例子:
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'','','','','',''
,'','','','','','',''
from dbo.Sheet2$
如果不允许为空,就将''换成任何你想要初始化的数据,如果允许为NULL,可以换成NULL。
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'','','','','',''
,'','','','','','',''
from dbo.Sheet2$
如果不允许为空,就将''换成任何你想要初始化的数据,如果允许为NULL,可以换成NULL。
#6
谢谢各位。
#1
default(某个值) 默认值即可自动赋值。
如果是可变值的话,可以改变recordID 为计算列。
如果是可变值的话,可以改变recordID 为计算列。
#2
insert 表B(字段列表)
select 字段列表 from 表A
(你要自动赋值就直接col=计算公式之类的东西)
select 字段列表 from 表A
(你要自动赋值就直接col=计算公式之类的东西)
#3
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan
from dbo.Sheet2$
这样会提示列数不一样。多出来的列的该怎么处理?
我是新手,请详细指点。谢谢。
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan
from dbo.Sheet2$
这样会提示列数不一样。多出来的列的该怎么处理?
我是新手,请详细指点。谢谢。
#4
多出来的列,LZ需要给出一个值。
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'...
from dbo.Sheet2$
不过多出来的列,可以不写出,当然前提是这列可以为空值,或有默认值,示例如下:
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'
from dbo.Sheet2$
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'...
from dbo.Sheet2$
不过多出来的列,可以不写出,当然前提是这列可以为空值,或有默认值,示例如下:
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'A','B'
from dbo.Sheet2$
#5
借楼主代码举个例子:
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'','','','','',''
,'','','','','','',''
from dbo.Sheet2$
如果不允许为空,就将''换成任何你想要初始化的数据,如果允许为NULL,可以换成NULL。
insert into dbo.td_Accept_Errata (
SDate, EntRegNO, EntName, RemoveDept, Reason, OperateMan, RecordID, EntID, cCodeBar, RemoveMan, RemovePhone, SMan, SMode, SReason, SState, OperateDate, PassMan, IsValid, IsDW
)
select Sdtate, EntRegID, EntName, RemoveDeptCode, Reason, PassMan,'','','','','',''
,'','','','','','',''
from dbo.Sheet2$
如果不允许为空,就将''换成任何你想要初始化的数据,如果允许为NULL,可以换成NULL。
#6
谢谢各位。