本文介绍了SQL SP-将记录从一个表复制到多个表,条件是在一个字段上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想创建一个将记录从表0复制到三个表的SP.我在表0上有一列说COL1,将其与表tabl1,table2,table3的特定值说1,2,3分别进行比较,因此插入了行到相应的表格.

我也想在插入
时将table0的数据类型转换为表的data-type字段并且值(ROW)不应重复.

感谢Abhishek
印度高级软顾问.

Hi,
I want to create a SP which copies records from a table0 to three tables.i have a column on table0 say COL1 which is compared to a specific value say 1,2,3 for tables tabl1,table2,table3 respectively thus the row is inserted to tables accordingly.

also i want to convert the data-types of table0 to the data-type field of the table while inserting
and the value(ROW) shouldn''t be duplicated.

Thanks Abhishek
Senior soft consultant,India.

推荐答案

INSERT INTO tabl1 (col1, col2, ...)
       SELECT col1, cast(col2 as int), ...
       FROM table1
       WHERE Col1 = 1



cast 正在为您执行转换操作.

对所有三个表重复此语句.

还可以考虑阅读以下页面:
http://msdn.microsoft.com/en-us/library/ms188263.aspx [ ^ ]

http://devguru.com/technologies/t-sql/7124.asp [ ^ ]

我敢肯定,将这三个语句转换为存储过程对您来说是最简单的部分.

希望对您有所帮助.



The cast is doing the convert operation for you.

Repeat this statement for all three tables.

Also consider reading these pages :
http://msdn.microsoft.com/en-us/library/ms188263.aspx[^]

http://devguru.com/technologies/t-sql/7124.asp[^]

I''m sure that converting these three statements into a storedprocedure is the easiest part for you.

Hope it helps.


这篇关于SQL SP-将记录从一个表复制到多个表,条件是在一个字段上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 17:54