|
Posted by Erland Sommarskog on 09/30/89 12:00
(RodStrongo1@gmail.com) writes:
> The two queries are pertaining to domestic vs intl. It does a lookup
> for a country code, and case 1 of domestic, case 2 of international.
> The query I copied in here is the intl. Both queries run from the
> same table, but searching the domestic entries runs smoothly.
>
> Running the sp_spaceused returns:
> name rows reserved
> data index_size unused
> distributors_detail 973 440 KB 368 KB 56 KB > 16 KB
Less than a megabyte. The poor search conditions should not be an issue.
But when I reviewed your original post, I notice that the SQL that
is generated is not correct. There is this:
> sql = sql& "isNull(cust_code_3,'') in('', 'CH') AND "
> sql = sql & " or LEFT(cust_no, CHARINDEX('-', cust_no) - 1) = '"& trim(arrDist_id_physical(iIntern)) &"'"
> sql = sql& "LEFT(distributors_detail.cust_no, CHARINDEX('-', distributors_detail.cust_no) - 1) IN ("
The line in the middle does not fit in. AND can be followed by OR
and a string literal cannot be followed by a call to a system function.
Mind you, reading SQL code which is so entwined with client code is
difficult. And difficult to maintain.
In any case, it does not seem that you have posted the actual query
you have problem with. Or at least, I would expect a completely
different error than a timeout error for a query that does not
compile. So that leaves me a bit in the dark.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|