使用SQL语句进行数据迁移(by quqi99)

                                             使用SQL语句进行数据迁移(by quqi99) 


作者:张华 发表于:2007-12-03  ( http://blog.csdn.net/quqi99 )

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明。

 

1、例如有表:td_question(question_title,question_time,........),现有假设通过前一部分的工作已经将时间放入了标题字段的末尾,即例如在question_title字段中的值为“外商投资企业应在什么期限内办理所得税汇算清缴?2007/11/15”。我们现在需要将时间2007/11/15提出来拼成20071115000000的格式置入question_time字段中?

答:

update consultor.td_questions set question_time=replace(substring(question_title,len(question_title)-9,len(question_title)),'/','') + '000000'

在导入过程中,我遇到如下问题,

首先,我开始通过right(question_title,patindex(question_title,'%200_/__/__%'))函数来在标题字段中找到2007/11/15,可是发现patindex函数定位不准,最后只好改用substring替换。

其次,在找到2007/11/15之后,本来我开始是通过convert(varch(8),right(question_title,patindex(question_title,'200_/__/__')),112)函数将其将化为20071115格式,但是不行,后来改为通过replace替换

2、例如:td_answer表中也有answer_time字段需要设置同样的值时,

update td_answer set td_answer.answer_time=q.question_time from td_questions q where td_answer.answer_question=q.question_code
注意:td_answer 后面不能跟别名,不然报错
3、例如,如有表t_person(id,name)与表jobreport(id,name,age),要将t_person中的name字段迁移到jobreport表中的name字段中去。

insert into jobreport(name) (select name from t_person)

4、将同一个表如t1(id,a,b,c)的a字段更新到b字段中去。

得用别名,

update t1 z1 set a=(select b rom t1 z2 where z1.id=z2.id)

commit();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

quqi99

你的鼓励就是我创造的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值