June 9, 2008 at 11:50 am
Hello Please Help me OUT,
I am trying to insert data from different tables into single table
Say I have a result table
resultTB with following columns
[resID] (int)identity , [PQID] int is not null, [col1] navarchar , [col2] nvarchar, [newColID]is not null
I have my results in different tables, following is my list
TB1
[PQID] int is not null, [col1] nvarchar , [col2] nvarchar
I have to insert specific data into result table from TB1 for specific PQID
along with that I have newColID= '1'
So how can I insert these two separate values into result table..
Can anyone please suggest me any way to resolve this problem through sql programming
June 9, 2008 at 12:17 pm
1.If your new column is static then
declare @newColID int, @PQID int
Set @newColID = 1
set @PQID =1234
Insert into resultTB( [PQID] , [col1] , [col2], [newColID])
select PQID,col1,col2, @newColID
from TB1 where TB1.[PQID] = @PQID
2.If your new column resides in another table(TB2)
If your new column is in a different table (related to TB1 through PQID)
Insert into resultTB( [PQID] , [col1] , [col2], [newColID])
select TB1.PQID,TB1.col1,TB1.col2, TB2.newColID
from TB1 INNER JOIN TB2 ON TB1.PQID = TB2.PQID
where TB1.[PQID] = @PQID
Or
Insert into resultTB( [PQID] , [col1] , [col2], [newColID])
select TB1.PQID,TB1.col1,TB1.col2, TB2.newColID
from TB1 , TB2
where TB1.[PQID] = @PQID
and TB1.PQID = TB2.PQID
Hope this is what u are looking for.
June 9, 2008 at 12:19 pm
Aiwa,
I am confused by the source of your data to be inserted into resultTB. You say you have 2 different tables as source, but only list TB1.
Also, is newColID a column in TB1?
If TB1 is your only source table...
INSERT into resultTB
(PQID,col1,col2,newColID) --notice we do not explicity insert the identity column
SELECT PQID,col1,col2,newColID
FROM TB1 where PQID = ? and newColID = 1
Todd Carrier
MCITP - Database Administrator (SQL 2008)
MCSE: Data Platform (SQL 2012)
June 25, 2008 at 4:54 am
i want to insert multiple data into multiple tables column
June 25, 2008 at 6:51 am
habib_nub (6/25/2008)
i want to insert multiple data into multiple tables column
You need to include a wee bit more info about what you want to do than that. Otherwise, the answer is simply "Make a SELECT to select the multiple data that you want and use it in one or more INSERTs to insert into multiple tables column."
You might take a peek at the link in my signature and you might want to make you're own thread instead of piggy backing on someone else's post...
--Jeff Moden
Change is inevitable... Change for the better is not.
April 20, 2012 at 3:07 pm
After a new posting has been applied I am removing my request.
April 20, 2012 at 6:32 pm
Please don't hijack old threads. If you have a new question, start a new thread.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
April 20, 2012 at 9:09 pm
My apologies to the Business Intelligence Analyst with no tact.
I didn't hijack the threat. I wasn't paying attention. My apologies to the Forum Moderators.
I'll ask question elsewhere.
June 23, 2012 at 2:51 am
Hi,
I need your help on a similar case
I need to insert data from different tables into single table
I've a table named costs
and I've to fill it with datas from 3 tables: trademark,tariff and currency
Iam little bit confused
well the all thing Iam working on is while generating a template "word file"monitored by a stored procedure.
this sp should include this insert code in order that the table will be filled automatically once a template is generated.
I don't know if it sounds clear for you.
I hope that someone knows how to deal with that
and thank you anyway
June 25, 2012 at 10:41 am
zineb (6/23/2012)
Hi,I need your help on a similar case
...
Please open the new thread!
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy