私は次のSQLでいくつかのデータを取得するアプリケーションを持っています:
SELECT Sum(fieldname) AS fieldNameHere,
Sum(Cast(error AS INT)) AS Error,
Sum(jsperror) AS JSPError,
Sum(linkerror) AS LinkError
FROM schemaname.sessiondata session
WHERE starttime >= :startTime0
AND starttime < :endTime0
AND fieldname = :fieldNameVal0
UNION ALL
SELECT Sum(fieldname) AS fieldNameHere,
Sum(Cast(error AS INT)) AS Error,
Sum(jsperror) AS JSPError,
Sum(linkerror) AS LinkError
FROM schemaname.sessiondata session
WHERE starttime >= :startTime1
AND starttime < :endTime1
AND fieldname = :fieldNameVal1
UNION ALL
SELECT Sum(fieldname) AS fieldNameHere,
Sum(Cast(error AS INT)) AS Error,
Sum(jsperror) AS JSPError,
Sum(linkerror) AS LinkError
FROM schemaname.sessiondata session
WHERE starttime >= :startTime2
AND starttime < :endTime2
AND fieldname = :fieldNameVal2
コードのデバッグと調査のパラメーター値は次のとおりです。
startTime0=Wed Sep 12 22:00:00 BST 2012
endTime0=Wed Sep 12 23:00:00 BST 2012
hitPrices0=1
startTime1=Wed Sep 12 23:00:00 BST 2012
endTime1=Thu Sep 13 00:00:00 BST 2012
hitPrices1=1
startTime2=Thu Sep 13 00:00:00 BST 2012
endTime2=Thu Sep 13 01:00:00 BST 2012
hitPrices2=1
次に、SQL-server management studioで次のSQLを実行すると、正しいデータが提供されます。
SELECT Sum(fieldname) AS fieldNameHere,
Sum(Cast(error AS INT)) AS Error,
Sum(jsperror) AS JSPError,
Sum(linkerror) AS LinkError
FROM schemaname.sessiondata session
WHERE starttime >= '2012-09-12 22:00:00'
AND starttime < '2012-09-12 23:00:00'
AND fieldname = 1
UNION ALL
SELECT Sum(fieldname) AS fieldNameHere,
Sum(Cast(error AS INT)) AS Error,
Sum(jsperror) AS JSPError,
Sum(linkerror) AS LinkError
FROM schemaname.sessiondata session
WHERE starttime >= '2012-09-12 23:00:00'
AND starttime < '2012-09-13 00:00:00'
AND fieldname = 1
UNION ALL
SELECT Sum(fieldname) AS fieldNameHere,
Sum(Cast(error AS INT)) AS Error,
Sum(jsperror) AS JSPError,
Sum(linkerror) AS LinkError
FROM schemaname.sessiondata session
WHERE starttime >= '2012-09-13 00:00:00'
AND starttime < '2012-09-13 01:00:00'
AND fieldname = 1
注:これはstartDateとendDateの間違いではなく、パラメーターはフィールドとは異なります。startDateおよびenddateパラメーターは、その特定の間隔のstartdatetimeおよびenddatetimeを表します。startDateフィールドは、セッションの開始時刻を表します。
アプリで返された誤った結果:
[null, null, null, null]
[2, 1, 0, 0]
[null, null, null, null]
そしてsqlsmsからの正しい結果:
NULL NULL NULL NULL
NULL NULL NULL NULL
NULL NULL NULL NULL
なぜなのかわからないのですか?