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)
 Insert values to a temp table from the views

Author  Topic 

obezyanka
Starting Member

24 Posts

Posted - 2007-09-24 : 12:45:42
I created three views that I need to insert into a temp table. What's the best way to do it?

Kristen
Test

22859 Posts

Posted - 2007-09-24 : 12:53:49
[code]
INSERT INTO TempTable(Col1, Col2, ...)
SELECT Col1, Col2, ...
FROM View1
WHERE ...

INSERT INTO TempTable(Col1, Col2, ...)
SELECT Col1, Col2, ...
FROM View2
WHERE ...

INSERT INTO TempTable(Col1, Col2, ...)
SELECT Col1, Col2, ...
FROM View3
WHERE ...
[/code]
or am I missing something?

Kristen
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-24 : 12:54:05
If you meant separately,

INSERT INTO #tmptable (....)
SELECT ....
FROM dbo.view1

INSERT INTO #tmptable (....)
SELECT ....
FROM dbo.view2

INSERT INTO #tmptable (....)
SELECT ....
FROM dbo.view3



or you can also use UNION/UNION ALL.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

obezyanka
Starting Member

24 Posts

Posted - 2007-09-24 : 13:02:55
Is it a stored procedure?
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-24 : 13:10:49
quote:
Originally posted by obezyanka

Is it a stored procedure?



Is what a stored procedure?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

obezyanka
Starting Member

24 Posts

Posted - 2007-09-24 : 13:11:53
This INSERT INTO statement
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-24 : 13:13:45
They are just 3 separate T-SQL statements. You can put them into a proc if like to.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

obezyanka
Starting Member

24 Posts

Posted - 2007-09-24 : 13:15:08
What's the syntax to put them in the procedure?
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-24 : 13:55:44
Please refer books on line.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-25 : 10:38:20
Cross posting
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=89949



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -