Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SELECT * INTO TABLE Expand / Collapse
Author
Message
Posted Friday, February 7, 2014 4:02 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 7:31 AM
Points: 169, Visits: 268
Hi

how can I archive to SELECT * INTO existing table without listing column names?
Post #1539082
Posted Friday, February 7, 2014 4:12 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 21, 2014 9:19 AM
Points: 2,826, Visits: 8,462
Not quite sure what you're asking

Select * into Table_A from Table_B




Post #1539085
Posted Friday, February 7, 2014 4:13 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, June 26, 2014 4:08 AM
Points: 708, Visits: 3,286
If the target table already exists then you would need to use INSERT INTO

I always prefer to list the column names in my INSERT INTO and SELECT statements, however you don't have to.

Example:

CREATE TABLE SSC_Target (Column1 INT, Column2 INT, Column3 INT)

CREATE TABLE SSC_Source (Column1 INT, Column2 INT, Column3 INT)

INSERT INTO SSC_Source VALUES (1, 2, 3), (4, 5, 6)

INSERT INTO SSC_Target
SELECT * FROM SSC_Source

SELECT * FROM SSC_Target
SELECT * FROM SSC_Source

DROP TABLE SSC_Target
DROP TABLE SSC_Source



---------------------------------------------------------


It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
David Edwards - Media lens

Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
Howard Zinn
Post #1539086
Posted Friday, February 7, 2014 4:19 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 7:31 AM
Points: 169, Visits: 268
I had this code

select *
INTO Hosea_tempTable
from Hosea_tblDATA_Product_Reports


I see my error was select, I had to insert.
Post #1539088
Posted Friday, February 7, 2014 4:23 AM This worked for the OP Answer marked as solution


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, June 26, 2014 4:08 AM
Points: 708, Visits: 3,286
hoseam (2/7/2014)
I have this code

select *
INTO Hosea_tempTable
from Hosea_tblDATA_Product_Reports


and I get this error;
There is already an object named 'Hosea_tempTable' in the database


Yes, that's because SELECT INTO attempts to create a table that already exists in your database. You want to be using INSERT INTO instead.


---------------------------------------------------------


It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
David Edwards - Media lens

Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
Howard Zinn
Post #1539090
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse