954,119 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

INSERT CLAUSE using SUB-QUERY

I'm trying to populate a table from a sub-query.

CREATE TABLE test
(
ID int
)


INSERT INTO test
VALUES (SELECT [Customer Id] 
FROM   [Customers])

QUESTION:
I know you can do this in ORACLE but Is something like this possible in T-SQL.

I can also write something like this in SQL which achieves the same result but I will lose the datatype,

SELECT [Customer Id] 
INTO test
FROM   [Customers]

Any suggestions is greatly appreciated.

Letscode
Junior Poster
175 posts since Feb 2005
Reputation Points: 11
Solved Threads: 6
 

[HTML]
INSERT INTO test
(SELECT [Customer Id]
FROM [Customers])
[/HTML]

Works fine.

Letscode
Junior Poster
175 posts since Feb 2005
Reputation Points: 11
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You