使用SQL语句进行数据迁移(by quqi99)
2007-11-12 11:37
274 查看
使用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();
作者:张华 发表于: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();
相关文章推荐
- 使用SQL语句进行数据迁移之二(by quqi99)
- 在Hibernate中使用HibernateTemplate来进行包含sql语句的查询
- Excel 中使用SQL 语句查询数据(七)-----用LIKE 运算符进行模糊匹配查询
- 动态组装sql语句时使用str = where = "1=1"; 然后再进行追加对性能的影响
- 使用SQL语句对数据进行MD5加密
- 在ORM框架中使用原生sql语句进行聚合查询遇到的问题
- 使用mybatis进行批量处理sql语句
- 使用SQL语句对Oracle数据库数据进行拼接
- 使用SQL语句在K3里进行反结帐- -
- Hibernate中使用原生的sql语句进行查询操作
- 使用SQL语句对数据进行简单报表汇总
- 使用alibaba Druid 对sql 语句进行校验
- MySQL中使用SQL语句对字段进行重命名
- MySQL中使用SQL语句对字段进行重命名
- 一步一步教你使用AgileEAS.NET基础类库进行应用开发-基础篇-使用UDA操纵SQL语句
- C#中使用SQL的BULK语句,进行大数据量操作
- 在Excel中使用SQL语句对多个数据表进行精确筛选
- Python与开源GIS:在OGR中使用SQL语句进行查询
- 在Excel中使用SQL语句对多个数据表进行精确筛选 (查询)
- excel内一键进行sql查询(使用方法 1.选择’需要进行sql查询区域 包括字段名 2 输入sql语句 3.选择输出数据的单元格)