Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to ente data twice into a tbl from other tbl?

Author  Topic 

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-01-08 : 10:50:27
I have tblA with below columns

Col1 -----Col2-------Col3--------Col4---------Col5

2315 -----DER---------34----------TR----------email (1st row)
4325 -----MaRK---------DATA--------UT----------email (2nd Row)

MY QUESTION : How to enter each row from tblA into the other table(tblB) like below.
1st Modified row of the inserted table from 1 st row of tblA
2nd Modified row of the inserted table from 1 st row of tblA



Sol1 -----Sol2-------Sol3--------Sol4------Sol5
2315 -----DER67---------34----------RTR-----email (1st from tblA)
2315 -----DER67---------64----------TRT-------email (1st row tblA)

Also I need to insert data sorted by column Sol1. All the above said is a template table to be imported in to oUR ERP software. PLEASE HELP

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-08 : 10:54:49
you need to state the business rules how to get from
this
quote:
2315 -----DER---------34----------TR----------email (1st row)

to this
quote:
Sol1 -----Sol2-------Sol3--------Sol4------Sol5
2315 -----DER67---------34----------RTR-----email (1st from tblA)
2315 -----DER67---------64----------TRT-------email (1st row tblA)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-01-08 : 11:06:11
Can you explain How??

quote:
Originally posted by khtan

you need to state the business rules how to get from
this
quote:
2315 -----DER---------34----------TR----------email (1st row)

to this
quote:
Sol1 -----Sol2-------Sol3--------Sol4------Sol5
2315 -----DER67---------34----------RTR-----email (1st from tblA)
2315 -----DER67---------64----------TRT-------email (1st row tblA)



KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-08 : 11:18:31
You need to give more explanation about how you will get values specified in o/p.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-08 : 11:27:32
quote:
Originally posted by Vaishu

Can you explain How??

quote:
Originally posted by khtan

you need to state the business rules how to get from
this
quote:
2315 -----DER---------34----------TR----------email (1st row)

to this
quote:
Sol1 -----Sol2-------Sol3--------Sol4------Sol5
2315 -----DER67---------34----------RTR-----email (1st from tblA)
2315 -----DER67---------64----------TRT-------email (1st row tblA)



KH
[spoiler]Time is always against us[/spoiler]







Not me. You. You need to tell us HOW.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-01-08 : 11:36:24
Hi

I am about enter data from one table (tbl A)insert into 5 other tables. one of the 5 table need to have 2 rows for each Number in Col1 of tblA.
ex1: tblA
Col1
123 (if the Col1 have 123 then Sol1 of tbl B must have 123 and column 'linenum' must have the value of '32' SECOND row of the tbl B
123 and 'linenum' must have the value of '64'.
ex2: tblB
Sol1----LineNum
123-----32
123-----64

I can use SQL procedure to get and modify the record from tblA.

In short how insert one data as two row
ex : Selcet A AS 123, A AS 123 from tbl A

INSERT INTO tblB (Sol1)

Expected result is like below

ex: tbl B
Sol1
123
123


quote:
Originally posted by visakh16

You need to give more explanation about how you will get values specified in o/p.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-08 : 11:52:41
And where do you get other values (RTR,TRT.. from TR etc)?
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-01-08 : 12:06:17
Other values not necessary. If you let me know how to do for 1 value thats enough.

Thanks

quote:
Originally posted by visakh16

And where do you get other values (RTR,TRT.. from TR etc)?

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-08 : 12:18:03
Try this:-

INSERT INTO tblB (Sol1,Sol2,..
SELECT t.Col1,t.Col3,.....
FROM
(SELECT Col1,Col2,Col3,other values FROM tblA
UNION ALL
SELECT Col1,Col2+'67' AS 'Col2',(Col3*2) AS 'Col3',other values from tblA)t
ORDER BY t.Col1

Make sure that both select statement inside contains equal columns with corresponding columns being of same type.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-01-08 : 15:04:08
Something like this?
INSERT Table2
(
Sol1,
Sol2,
Sol3,
Sol4,
Sol5
)
SELECT
Table1.Col1,
Table1.Col2,
Foo.Num,
Table1.Col4,
Table1.Col5
FROM
Table1
CROSS JOIN
(
SELECT 32 AS Num
UNION ALL SELECT 64
) AS Foo
Go to Top of Page
   

- Advertisement -