Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 16-Jan-12 19:05pm
v2

1 solution

You can use some SQL like this one :

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


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900