Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 INSERT INTO, EXCLUDING ONE COLUMN

Author  Topic 

stahorse
Yak Posting Veteran

86 Posts

Posted - 2014-02-07 : 08:24:51
Hi

Is there a way I can:
INSERT INTO TableA
SELECT * FROM TableB
but exclude one column from TableB?

My TableB has ID which is IDENTITY(1,1), I want to select everything to TableA except the ID.
Without listing the columns

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-02-07 : 11:38:05
quote:
Originally posted by stahorse


Without listing the columns

No.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-10 : 08:52:49
quote:
Originally posted by stahorse

Hi

Is there a way I can:
INSERT INTO TableA
SELECT * FROM TableB
but exclude one column from TableB?

My TableB has ID which is IDENTITY(1,1), I want to select everything to TableA except the ID.
Without listing the columns




You cant do it
but you can generate the required column list easily using catalog view INFORMATION_SCHEMA.COLUMNS. just filter for TABLE_NAME = 'Your Table Name' to get all columns. copy and paste the result into your actual query to get column list. Add a filter as

..
WHERE COLUMN_NAME <> 'ID Column name'

to exclude the id column from the list

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -