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
 Urgent Help in temporary table

Author  Topic 

1sabine8
Posting Yak Master

130 Posts

Posted - 2008-09-24 : 09:19:05
Hi,
I have a temporary table in a stored procedure. Inside this table i'm inserting rows. I need to keep these rows and insert after them new rows from a new query. So how can i make the second query insert data after the last row in the temporary table?
It's urgent please!
Here's the code.

CREATE TABLE #DineInLoyalCustomers(
ContactId nvarchar(60) )
INSERT INTO #DineInLoyalCustomers(ContactId)
SELECT DISTINCT dbo.FilteredContact.contactid
FROM dbo.FilteredContact INNER JOIN
dbo.FilteredNew_dineintakeawaycommentcard ON dbo.FilteredContact.contactid = dbo.FilteredNew_dineintakeawaycommentcard.new_contactid
drop table #DineInLoyalCustomers

So how do i add the second query?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-24 : 10:30:47
You could add a (sort) column to the table. Make the values all "1" for the first query, make the values all 2 for the 2nd query. Then when you SELECT from the table order by your (sort) column.

btw,
Unless there is a CLUSTERED index rows aren't ordered at all, they are in a heap.

Be One with the Optimizer
TG
Go to Top of Page

1sabine8
Posting Yak Master

130 Posts

Posted - 2008-09-25 : 03:31:37
Hi,
Thanks for your reply but i found the solution.
I wrote two insert statement on the same temporary table so the rows were added one block (from query 2) after the other(from query 1).
Thanks again
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 04:14:15
quote:
Originally posted by 1sabine8

Hi,
Thanks for your reply but i found the solution.
I wrote two insert statement on the same temporary table so the rows were added one block (from query 2) after the other(from query 1).
Thanks again


actually the order in which the records are inserted into table does not matter. you can always retrieve the records in order you want by specifying order by means of ORDER BY clause.
Go to Top of Page
   

- Advertisement -