Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to SELECT * INTO x FROM y join z ?????

Status
Not open for further replies.

christheprogrammer

Programmer
Jul 10, 2000
258
CA
Hiya
I want to do this:

SELECT * INTO [##table1] FROM [dbo].[##table2]
INNER JOIN [##table3]
ON [##table2].field1 =[##table3].field1)

keep in mind that [##table2].field1 and [##table3].field1
have the same column name. It is impossible to create a table having 2 columns with the same name. Is it possible to do this select statement somehow but only with one of the two fields in the result set?
Thanks a bunch,

Chris

Chris Grandin
grandin1@yahoo.com
Malaspina has a great computer science program. Top-Notch.
 
Try this.

SELECT a.field1, a.field2, a.filed3, b.field1 As field1b, b.field2 as field2b, ...
INTO ##table1
FROM ##table2 a
INNER JOIN ##table3 b
ON a.field1 = b.field1

Or if field1 is the only duplicated column then you could do the following.

SELECT a.*, b.fieldA, b.fieldB, ... b.fieldN
INTO ##table1
FROM ##table2 a
INNER JOIN ##table3 b
ON a.field1 = b.field1
Terry
------------------------------------
Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward.
 
Thanks for the swift reply, unfortunately both tables have over 200 fields, and I want all of them included except the one I am using for the join... See the dilemma? This must have come up before. I cannot see how SQL could have survived without some mechanism for this scenario. I really want to do this:

SELECT a.*, b.1,b.2,b.3,b.4,........ INTO ... etc

but without writing 200 b.x 's
Help would be greatly appreciated!
Thanks
Chris Chris Grandin
grandin1@yahoo.com
 
why not dynamically build the sql statement using a query to sysobjects? at any rate, there is no way to exclude columns and besides that, it is bad programming to use 'select * ' anyway.


Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top