MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 11th, 2004, 09:12 AM
viju_vijay viju_vijay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 9 viju_vijay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 28 sec
Reputation Power: 0
Question Inserting Values from multiple tables to only one column of a seperate table

Hi all,

I want to produce some output for Mainframe application. For that I want to insert values from multiple table as source to a single column (huge in size)of a different table (Destination table). There may be same related records in all of the source tables with the primary key. When I export values from the source tables , each related records should be insterted to the destination table's field (multiple entries for each table). Please advise.

Thanks

Reply With Quote
  #2  
Old December 11th, 2004, 11:01 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,717 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 18 h 31 m 7 sec
Reputation Power: 986
you mean UPDATE a column, not INSERT, right?

because if you insert values into a column, all the other columns in the destination table will be null or default
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old December 13th, 2004, 02:23 AM
viju_vijay viju_vijay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 9 viju_vijay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 28 sec
Reputation Power: 0
Quote:
Originally Posted by r937
you mean UPDATE a column, not INSERT, right?

because if you insert values into a column, all the other columns in the destination table will be null or default



Hi,

Thanks for the quick reply.

Yes it should be null. Actully I want to produce a text file output from multiple tables using where condition. The exact column width should be reflected for each colum on the text file. The column should not be seperated by comma, tab or a space. The next column shoul start exactly after the previous column ends.

If i can export all the values from multiple table the single column of the destination (Concatening the column, Like col1 + col2 + col3 so on) I would be able to produce the desired result.

As if now, I am able to extract values from only one table as if now. Please advise if I can export values from multiple tables to a single colum of a destination table at once.

Reply With Quote
  #4  
Old December 13th, 2004, 06:17 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,717 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 18 h 31 m 7 sec
Reputation Power: 986
okay, yes, you can do this

you need concatenation, like col1 + col2 + col3

you also need conversion to fixed width for any varchar columns, like convert(char(25),varcharfield)

Reply With Quote
  #5  
Old December 16th, 2004, 06:21 AM
lvramani lvramani is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 2 lvramani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by r937
okay, yes, you can do this

you need concatenation, like col1 + col2 + col3

you also need conversion to fixed width for any varchar columns, like convert(char(25),varcharfield)


You can construct the query as follows

say you have 2 tables called order and invoice

SELECT
CONVERT(VARCHAR,o.orderid) + ' ' + CONVERT(VARCHAR,i.invoiceid) + ' ' + o.customername,CONVERT(VARCHAR,i.invoicedate) AS CustomerDetail INTO LogCustomerDetails
FROM order o, invoice i
WHERE o.orderid = i.invoiceid

I think this should solve your problem.

Reply With Quote
  #6  
Old December 16th, 2004, 07:06 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,717 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 18 h 31 m 7 sec
Reputation Power: 986
lvramani, conversion to CHAR with a specific width is required, not VARCHAR

also, specify a style for the date conversion

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Inserting Values from multiple tables to only one column of a seperate table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway