In my ASP page, I have Server.ScriptTimeout = 100, I have a query that I run calling SQL Server 7.0 and it never seems to timeout.
Has anyone ran into this problem before?
ok..lets step back a bit and come to the main problem...so when you run this query...do you get any errors...what actually happens and what is this query doing..may be there is an alternate efficient way for this query...
I ran my query through the Query Analyzer. I am using a UNION query. If I run my first query, it pulls back ZERO records in under a second. I run the second part of my query and I pull back 694 rows in under a second. But when I run both together with a UNION, it is hanging.
I realize at this point that I maybe should move to the SQL Server forum, what do you think?
if you want..i can take a look at the query before you can post it in sql forums...of course i will look there too...because i participate in that forums too...
just post some sample data and results you want to see...also post the queries you tried...we will see if we can come up with the solution...
or else you can go ahead and post it in sql server forums...you are sure to get the reply there...lot of experts there
Howdy DotNetGnat,
Here is the query:
SELECT Company.CompanyID, Offices.OfficeID, Offices.ChangeID, Offices.CreatedBy, Offices.OfficeName, CompanyType.CompanyTypeDesc, Company.CompanyName, IndustryType.IndustryTypeDesc, Offices.City, ServiceType.ServiceTypeDesc FROM IndustryType INNER JOIN (ServiceType INNER JOIN (CompanyType INNER JOIN (CompanySpecs INNER JOIN (Company LEFT JOIN Offices ON Company.CompanyID = Offices.CompanyID) ON CompanySpecs.CompanySpecsID = Company.CompanySpecsID) ON CompanyType.CompanyTypeID = CompanySpecs.CompanyTypeID) ON ServiceType.ServiceTypeID = CompanySpecs.ServiceTypeID) ON IndustryType.IndustryTypeID = CompanySpecs.IndustryTypeID WHERE Offices.CreatedBy = 6623 AND CompanySpecs.IndustryTypeID = 1 AND CompanySpecs.CompanyTypeID = 2 AND Offices.ChangeID IS NOT NULL AND Offices.ChangeID NOT IN (SELECT OfficeID FROM SupportServiceAssignment WHERE CreatedBy = 6623 AND PropertyID = 3607)
UNION
SELECT Company.CompanyID, Offices.OfficeID, Offices.ChangeID, Offices.CreatedBy, Offices.OfficeName, CompanyType.CompanyTypeDesc, Company.CompanyName, IndustryType.IndustryTypeDesc, Offices.City, ServiceType.ServiceTypeDesc FROM IndustryType INNER JOIN (ServiceType INNER JOIN (CompanyType INNER JOIN (CompanySpecs INNER JOIN (Company LEFT JOIN Offices ON Company.CompanyID = Offices.CompanyID) ON CompanySpecs.CompanySpecsID = Company.CompanySpecsID) ON CompanyType.CompanyTypeID = CompanySpecs.CompanyTypeID) ON ServiceType.ServiceTypeID = CompanySpecs.ServiceTypeID) ON IndustryType.IndustryTypeID = CompanySpecs.IndustryTypeID WHERE Offices.ChangeID IS NULL AND CompanySpecs.IndustryTypeID = 1 AND CompanySpecs.CompanyTypeID = 2 AND (Offices.CompanyID = Offices.CreatedBy OR Offices.CreatedBy = 6623OR Offices.CreatedBy = 6624) AND Offices.OfficeID NOT IN (SELECT OfficeID FROM SupportServiceAssignment WHERE CreatedBy = 6623 AND PropertyID = 3607) AND Offices.OfficeID NOT IN (SELECT ChangeID FROM Offices WHERE ChangeID IS NOT NULL AND CreatedBy = 6623)
ORDER BY Company.CompanyName, Offices.OfficeName
Wow, I looked at the query numerous times and I didn't see the space missing. Thanks so much for that.
I ran the query without the order by clause and fixed the space and it runs in 1 second.
How come I can't use an order by clause?
How else can I order the records that are returned?
The ORDER BY clause applies to the entire result. You can only have one ORDER BY clause in a UNION query and it must be part of the last SELECT statement.
also change UNION to UNION ALL
so what i would suggest it change your query to look something like this...example:
Code:
SELECT au_lname FROM authors
UNION ALL
SELECT lname FROM Employee
ORDER BY au_lname
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.