If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Join help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-12, 02:45
buzmay buzmay is offline
Registered User
 
Join Date: Jan 2012
Posts: 44
Join help

Hi guys,

I am trying to make a join in between 2 tables. One table which we can called func has 2 columns a and column b.

The other table which is called export has 16 columns. I will like to make a join in these tables and insert the result of the join into another table i have.

The table that is going to have the information has 4 columns, so I will get 1 column information from table export, and the other 2 column from table func, the other column shall be left in blank for the time being.

The problem is also that when i make a select from table export, there are only some values i want to get, this are values from a period where there is only the periods 11.

Select Company, A and B
FROM FUNC, EXPORT where period = '1101', '1102', '1103'
insert into new table?

does anyone here can give me a hand?
Thanks in advance.

Last edited by buzmay; 01-17-12 at 03:45.
Reply With Quote
  #2 (permalink)  
Old 01-17-12, 03:53
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,280
Can you give some example data from both tables (including column names) and the column names of the destination table?
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #3 (permalink)  
Old 01-17-12, 04:07
buzmay buzmay is offline
Registered User
 
Join Date: Jan 2012
Posts: 44
Sure thanks,

table export has 16 columns which the one that is important only for me is the company column

table func has only 2 columns we can call them a and b.

the table that all the info is going to be is called table info and has the following columns:
company, a, b, result

so from table export which has 16 columns, I only want the column company, and from table func, both of the columns ie a&b

the prblem is that the column company has several companies, and i want only to select the companies that has 11 on its name, this info shall be inserted into the new table info.

Thanks in advance
Reply With Quote
  #4 (permalink)  
Old 01-17-12, 04:39
buzmay buzmay is offline
Registered User
 
Join Date: Jan 2012
Posts: 44
So what I have gotten now is this:

INSERT INTO INFO, SELECT COMPANY, A, B
FROM EXPORT, FUNC,
WHERE EXPORT = FUNC
AND EXPORT.PERIOD IN ('11A', '11B', '11C')
Reply With Quote
  #5 (permalink)  
Old 01-17-12, 04:56
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
try something like
INSERT INTO T1 (COMPANY,A,B)
SELECT COMPANY, A, B
FROM EXPORT INNER JOIN FUNC ON EXPORT.?? = FUNC.??
WHERE EXPORT LIKE '%11%'

replace ?? with columns to be joined
Reply With Quote
  #6 (permalink)  
Old 01-17-12, 05:15
buzmay buzmay is offline
Registered User
 
Join Date: Jan 2012
Posts: 44
Quote:
Originally Posted by mrpcguy View Post
try something like
INSERT INTO T1 (COMPANY,A,B)
SELECT COMPANY, A, B
FROM EXPORT INNER JOIN FUNC ON EXPORT.?? = FUNC.??
WHERE EXPORT LIKE '%11%'

replace ?? with columns to be joined
this made the trick, thanks a million, I really appreciate it
Reply With Quote
  #7 (permalink)  
Old 01-17-12, 05:22
mrpcguy mrpcguy is offline
Registered User
 
Join Date: Mar 2004
Posts: 140
i forgot a column name on the WHERE statement but i guess you already figured that out

WHERE EXPORT.COMPANY LIKE '%11%'
Reply With Quote
  #8 (permalink)  
Old 01-17-12, 05:24
buzmay buzmay is offline
Registered User
 
Join Date: Jan 2012
Posts: 44
Yes I did, but without your guidance I would still be lost. many thanks, and a lot of appreciation for Wim, which also tried to help
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On