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
 General SQL Server Forums
 New to SQL Server Programming
 Create a table from a view

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2011-12-13 : 11:42:27
Hello,

I have a view I want to insert it to a permanent table?

Would you please guide me to drive it?

Thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-13 : 11:44:59
[code]
INSERT INTO YourTable (Column1,Columne2,....)
SELECT Column1,Column2,...
FROM View
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

goligol
Posting Yak Master

128 Posts

Posted - 2011-12-13 : 11:53:10
Thank you.

I am using the following commands:

USE [trade]


INSERT INTO [dev].[8DigitsNaicsValueWeightShare_export]


SELECT [naics]
,[ust_code]
,[port]
,[all_qty_1_yr]
,[all_qty_2_yr]
,[all_val_yr]
,[all_air_val_yr]
,[all_air_wgt_yr]
,[all_ves_val_yr]
,[all_ves_wgt_yr]
,[all_cnt_val_yr]
,[all_cnt_wgt_yr]
,[all_border_val_yr]
FROM [trade].[dev].[8DigitsNaicsValueShare_exp]

GO

but gives me the error of:
Msg 208, Level 16, State 1, Line 5
Invalid object name 'dev.8DigitsNaicsValueWeightShare_export'.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-13 : 11:55:08
have you created the table dev.8DigitsNaicsValueWeightShare_export already?
if not you need to use SELECT ...INTO instead

SELECT [naics]
,[ust_code]
,[port]
,[all_qty_1_yr]
,[all_qty_2_yr]
,[all_val_yr]
,[all_air_val_yr]
,[all_air_wgt_yr]
,[all_ves_val_yr]
,[all_ves_wgt_yr]
,[all_cnt_val_yr]
,[all_cnt_wgt_yr]
,[all_border_val_yr]
INTO [dev].[8DigitsNaicsValueWeightShare_export]
FROM [trade].[dev].[8DigitsNaicsValueShare_exp]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

goligol
Posting Yak Master

128 Posts

Posted - 2011-12-13 : 11:59:06
Thank you so much. It worked!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-13 : 12:00:55
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -