Ouch! That was like the.. longest.. query that I've ever seen! I'm
surprised that it actually works and even more impressed that someone
actually figured that out... It might take a long time to run, since it
uses so many subqueries (if there's lots of data or even a moderate
amount of data). Are you sure there's no easier way to fetch your data?
Most subqueries can be re-written using a join and some more
where-comparisons instead...
Actually I'm more amazed that you actually can send that query and that
it works.. There's a slight chance that your problems might be solved by
rewriting that query... Maybe it's just to long or something, I don't
know. I will however not take the time to refactor that query... :)
Are you running PHP under Linux or Windows? You said that you only found
two queries that breaks? Wll, if the shorter ones works, but the longer
ones hangs, then maybe that's the problem...? :)
Regards,
Krister Karlström, Helsinki, Finland
Weaver Hickerson wrote:
Krister -
I've included the query below - If I paste it in query analyzer on 2000, or 2005 it works fine.
Just coming through PHP4 to 2005, it hangs. I actually don't get an error, and then the browser says the server is too busy to handle the request. Strange things like that. (I am using Zend Core with Apache and PHP 5). I will check for smalldatetime fields.
SELECT COUNT(DISTINCT C.CHART_ID) AS TOTAL,
SUM(ISNULL(FEE_SCHEDULE.FEE,0) * UNITS) AS TOTALFEE
FROM HL7 H,
CHART C
LEFT OUTER JOIN CHART_CODE D
LEFT OUTER JOIN CHART_CODE_MODIFIER CCM
ON CCM.CHART_CODE_ID = D.CHART_CODE_ID
AND CCM.CHART_CODE_MODIFIER_ID = (SELECT MIN(CHART_CODE_MODIFIER_ID)
FROM CHART_CODE_MODIFIER
WHERE CHART_CODE_ID = D.CHART_CODE_ID)
LEFT OUTER JOIN FEE_SCHEDULE
ON FEE_SCHEDULE.CPT_CODE = D.CHART_CODE
AND FEE_SCHEDULE.START_DATE <= (SELECT MSH_DTM
FROM HL7,
CHART,
CHART_CODE
WHERE CHART_CODE.CHART_ID = CHART.CHART_ID
AND CHART.HL7_ID = HL7.HL7_ID
AND CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
AND FEE_SCHEDULE.END_DATE >= (SELECT MSH_DTM
FROM HL7,
CHART,
CHART_CODE
WHERE CHART_CODE.CHART_ID = CHART.CHART_ID
AND CHART.HL7_ID = HL7.HL7_ID
AND CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
AND FEE_SCHEDULE.SENDING_FACILITY = (SELECT SENDING_FACILITY
FROM HL7,
CHART,
CHART_CODE
WHERE CHART_CODE.CHART_ID = CHART.CHART_ID
AND CHART.HL7_ID = HL7.HL7_ID
AND CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
AND FEE_SCHEDULE.CODE_TYPE = 'pro'
AND FEE_SCHEDULE.MODIFIER = CCM.MODIFIER
LEFT OUTER JOIN FEE_SCHEDULE FS
ON FS.CPT_CODE = D.CHART_CODE
AND FS.START_DATE <= (SELECT MSH_DTM
FROM HL7,
CHART,
CHART_CODE
WHERE CHART_CODE.CHART_ID = CHART.CHART_ID
AND CHART.HL7_ID = HL7.HL7_ID
AND CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
AND FS.END_DATE >= (SELECT MSH_DTM
FROM HL7,
CHART,
CHART_CODE
WHERE CHART_CODE.CHART_ID = CHART.CHART_ID
AND CHART.HL7_ID = HL7.HL7_ID
AND CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
AND FS.SENDING_FACILITY = (SELECT SENDING_FACILITY
FROM HL7,
CHART,
CHART_CODE
WHERE CHART_CODE.CHART_ID = CHART.CHART_ID
AND CHART.HL7_ID = HL7.HL7_ID
AND CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
AND FS.CODE_TYPE = 'pro'
AND (FS.MODIFIER = ''
OR FS.MODIFIER IS NULL)
ON D.CHART_CODE_ID IN (SELECT MIN(CHART_CODE_ID)
FROM CHART_CODE
WHERE CHART_ID = C.CHART_ID)
WHERE MSH_DTM >= '10/01/2008'
AND MSH_DTM < DATEADD(D,1,'10/31/2008')
AND H.HL7_ID = C.HL7_ID
AND CHART_CODE IN ('99281','99282','99283','99284',
'99285','99291')
AND C.STATUS = 6
AND H.SENDING_FACILITY = 'AEU'
ORDER BY 1
________________________________________
From: Krister Karlström [krister.karlstrom@xxxxxxxxx]
Sent: Wednesday, November 05, 2008 3:31 AM
To: Weaver Hickerson
Cc: PHP DB
Subject: Re: PHP4, mssql_* and SQL Server 2005
Hi!
Have you checked that the query is escaped correctly? All single quotes
(') needs to be escaped with another single quote, but that has been for
MS-SQL all the time so I'll doubt that the problem is escaping.
Another issue I noticed is that SQL Server 2005 handles SMALLDATETIME
coulmns slightly different, and the default formatting of the retuned
date is in some collations different than in SQL Server 2000. So if you
have any queries relying on a where clause that checks a SMALLDATETIME
column you might need to adjust the date format.
Migrating to SQL 2005 might also cause some problems with character
encoding, since SQL 2005 internally works with Unicode. At least for us
who needs other characters than 7-bit ASCII... I had big trouble with
moving ISO-8859-15 XML documents to a SQL Server 2005 Unicode server and
parsing them into a native XML datatype (which is a really nice
feature!), but the problems can be overcomed with a litte extra work...
You could also check that you use the correct protocol version of
FreeTDS, if you're running PHP under Linux. I don't know how PHP
connects to MS-SQL on Windows though.
Currently I have no other thoughts of what could cause your problems, at
least without not being able to actually see the failed queries.
Regards,
Krister Karlström, Helsinki, Finland
Chris wrote:
Please always cc the mailing list so others can offer extra
advice/suggestions etc.
Weaver Hickerson wrote:
they work in query analyzer.
ok so the queries aren't the problem.
do you get an error? what is it?
Might need to play with these settings:
http://www.php.net/manual/en/function.mssql-min-error-severity.php
http://www.php.net/manual/en/function.mssql-min-message-severity.php
And they seem to work on a new server I setup for testing that has
ZendCore and on which I installed the Microsoft PHP driver and ported
the code to that driver. :(
That does seem to point to the driver, not sure what other suggestions I
can offer.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php