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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert rows into Table A leveraging specifc values existing in Table B 1

Status
Not open for further replies.
Jul 21, 2009
13
US
I am using a variable set by the user to insert multiple rows into a table leveraging values from another table.

Insert into TableA (code, type)
values (@code, type)

The type value is from another table, but I want to insert a row in TAble A for each Type existing in Table B. So if 5 different types exist in Table B, I want to insert 5 rows with @code and each different Type in TableA.

I would be using like condition to insert certain Types from Table B (i.e. insert into TAble A a record for each 'SP%' type in Table B) but really just need to understand how to insert values without specifying each specific type value in the insert statement since new types are consistently getting added to Table B. Thanks!
 
Code:
Insert into TableA (code, type)
SELECT DISTINCT @code, type
FROM TableB

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top