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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How do I insert data from a query into a new table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-07-10 : 09:11:27
Julie writes "I have a database named Grow, with a table named Variety. I concatenated 3 columns from this table to make one column. I also tied in the VarietyID. How do I get the results from this query saved in a new table named Herbs

Use Grow
Create Table Herbs (VarietyID int, CommonNameFirst nvarchar(50) not Null, LatinNameFirst nvarchar (50) not Null)

Insert into Herbs values (ID, CommonName, LatinName)
select VarietyID as 'ID' VarietyName + ', ' + Family + ' ' + Genus as 'CommonName', Family + ' ' + Genus + ', ' + VarietyName as 'LatinName'
from Variety where Category = 'Herbs'

I need the data that is returned from the query saved in the new table Herbs. "

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-10 : 09:14:31
Try this



Insert into Herbs values (ID, CommonName, LatinName)
select VarietyID ,VarietyName + ', ' + Family + ' ' + Genus , Family + ' ' + Genus + ', ' + VarietyName
from Variety where Category = 'Herbs'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-10 : 09:14:51
Just drop the values

Insert into Herbs (ID, CommonName, LatinName)
select VarietyID as 'ID' VarietyName + ', ' + Family + ' ' + Genus as 'CommonName', Family + ' ' + Genus + ', ' + VarietyName as 'LatinName'
from Variety where Category = 'Herbs'

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -