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)
 Creating a table from results of a select query

Author  Topic 

Champinco
Yak Posting Veteran

54 Posts

Posted - 2006-11-15 : 19:19:26
I know this one is probably simple, and can be done in oracle by:
create table Test as
(
Select ....
)

I require the exact same functionality but in trans sql. That is a nested query that will copy into a new table based on the results from another query. Can this be done similarly as shown above or do i have to list the datatypes, sizes and use insert into statements?
Cheers
GK

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-11-15 : 19:23:45
[code]SELECT ...
INTO Test
FROM yourtable[/code]
Go to Top of Page

Champinco
Yak Posting Veteran

54 Posts

Posted - 2006-11-16 : 18:28:12
Im not sure what you mean, if have a select statement such as:

SELECT commission_summary.distributor as Distributor,
convert(varchar,commission_summary.commission_month,103) as 'Commission Date',
'$' + convert(varchar(50), sum(commission_summary.payment_this_period_carried_forward),1) as Total
from commission_summary
group by commission_summary.commission_month, distributor
order by commission_summary.commission_month desc, sum(commission_summary.payment_this_period_carried_forward) desc

I want to store the results of this query in a table, without having to do this manually. Is there some way i can store the results of this into another table: i.e:

Create table NEW
as
(
MY SELECT STATEMENT
)

Cheers
GK
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-11-16 : 20:00:20
Exactly like I told you before


SELECT commission_summary.distributor as Distributor,
convert(varchar,commission_summary.commission_month,103) as 'Commission Date',
'$' + convert(varchar(50), sum(commission_summary.payment_this_period_carried_forward),1) as Total
INTO NewTable
from commission_summary
group by commission_summary.commission_month, distributor
order by commission_summary.commission_month desc, sum(commission_summary.payment_this_period_carried_forward) desc
Go to Top of Page

Champinco
Yak Posting Veteran

54 Posts

Posted - 2006-11-16 : 20:25:30
Sweet,
Cheers Mate
GK
Go to Top of Page
   

- Advertisement -