SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Insert values to a temp table from the views
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

obezyanka
Starting Member

24 Posts

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

Kristen
Test

United Kingdom
22403 Posts

Posted - 09/24/2007 :  12:53:49  Show Profile

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 ...

or am I missing something?

Kristen
Go to Top of Page

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 09/24/2007 :  12:54:05  Show Profile  Visit dinakar's Homepage
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 - 09/24/2007 :  13:02:55  Show Profile
Is it a stored procedure?
Go to Top of Page

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 09/24/2007 :  13:10:49  Show Profile  Visit dinakar's Homepage
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 - 09/24/2007 :  13:11:53  Show Profile
This INSERT INTO statement
Go to Top of Page

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 09/24/2007 :  13:13:45  Show Profile  Visit dinakar's Homepage
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 - 09/24/2007 :  13:15:08  Show Profile
What's the syntax to put them in the procedure?
Go to Top of Page

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 09/24/2007 :  13:55:44  Show Profile  Visit dinakar's Homepage
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

Sweden
30241 Posts

Posted - 09/25/2007 :  10:38:20  Show Profile  Visit SwePeso's Homepage
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
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000