April 30, 2009 at 7:40 am
Dear All,
I am facing a very strange problem and i would highly appreciate if some one can help me.
i have 3 query and their results inserting into a temp table but the results of one query gets clubbed with another query.
Ex. 1 Query . insert into temp select top 2 * from table (5 columns)
Query . insert into temp values('','','','','') [extra line break for visibility]
2 Query . insert into temp select top 2 * from table1 (5 columns)
Query . insert into temp values('','','','','') [extra line break for visibility]
3 Query . insert into temp select top 2 * from table (5 columns)
Now few reocrds of query 1 result gets merge with query 3 result.
I am in dilemma why exactly it happens as i had tried delay for five seconds between each query.
Please suggest me to sort out this issue.
Thanks in Advance.
Vizay
April 30, 2009 at 8:19 am
I don't think I understood very well, can explain us what do you mean by "the results of one query gets clubbed with another query"? How about adding some sample data with the generated output for the sample data?
--Ramesh
April 30, 2009 at 11:49 pm
Hi ,
It means that when i select the list from temp table i found that few records of 1 query get display with the records of 3 query.
Ex . if 1 query returns 50 rows and and 3 query returns 20 rows then ... while reviewing the result set from temp table ... i see 45 records from 1 query and 25 records from 3 query.
As i have put some spaces between the queries so that it can be easily understood the result set of all 3 different queries...
I hope this time i had explained properly...
Regards,
Vizay
May 4, 2009 at 3:45 am
If you want the rows from a query to be returned in any specific order then you must specify the ORDER BY clause. For e.g.
SELECT * FROM SomeTempTable ORDER BY SomeKey
--Ramesh
May 5, 2009 at 9:26 am
Are you trying to get 3 different result sets with the queries?
Or
One table with the results from 3 different queries in it?
May 5, 2009 at 1:52 pm
You could add a "sort" column to your temporary table - like an Identity column that simply generates a sequential number, incremented for each row inserted into the table.
You can then use ORDER BY when querying from the temp table, which should give you the result you are after.
Chris
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply