943,699 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 28396
  • MS SQL RSS
Oct 18th, 2005
0

INSERT CLAUSE using SUB-QUERY

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

MS SQL Syntax (Toggle Plain Text)
  1. CREATE TABLE test
  2. (
  3. ID int
  4. )
  5.  
  6.  
  7. INSERT INTO test
  8. VALUES (SELECT [Customer Id]
  9. 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,

MS SQL Syntax (Toggle Plain Text)
  1. SELECT [Customer Id]
  2. INTO test
  3. FROM [Customers]

Any suggestions is greatly appreciated.
Similar Threads
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Oct 24th, 2005
0

Re: INSERT CLAUSE using SUB-QUERY

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

Works fine.
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: sql*plus or pl/sql question
Next Thread in MS SQL Forum Timeline: Help with a stored procedure





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC