我有两个表 想想把老表数据插入到新表中,在新表字段数据名称不一样(比如a表是员工姓名,b表是成员名字;把a表员旦讥测客爻九诧循超末工姓名数据批量插入到b表成员名字下),怎么写sql语句,
还有就是两个表中的许多数据类型不一致 怎么改?
非常谢谢
sql 2000 数据批量 插入新表
答案:3 悬赏:80
解决时间 2021-01-30 05:10
- 提问者网友:我是我
- 2021-01-29 22:12
最佳答案
- 二级知识专家网友:偏爱自由
- 2021-01-29 23:16
insert new_tbl (new_n1, new_n2) select old_n1, old_n2 from old_tbl
类型最好一样,有的数据库不支持
类型最好一样,有的数据库不支持
全部回答
- 1楼网友:如果这是命
- 2021-01-30 00:30
字段名不一样没关系!但是数据类型要一样!
insert旦讥测客爻九诧循超末 new_table(员工姓名)
select 成员名字
from old_table
最主要是数据顺序要一致。如果数据类型不同!那就转换数据格式
用convert 或cast 转换数据格式
- 2楼网友:恕我颓废
- 2021-01-29 23:42
循环插入: declare @mycounter int set @mycounter = 0 while (@mycounter < 2) begin waitfor delay '000:00:10' insert into time_by_day (time_id, the_date, the_year, month_of_year, quarter, day_of_month) select top 1 time_id + 1 as time_id, the_date + 1 as the_date, year(the_date + 1) as the_year, month(the_date + 1) as month_of_year, { fn quarter(the_date + 1) } as quarter, day(the_date + 1) as day_of_month from time_by_day order by time_id desc set @mycounter = @mycounter + 1 end
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |