SQL Server 2008にはかなり複雑なSQLクエリが約10個ありますが、クライアントは、Crystal Reports XIを介して(非ローカルWebアプリからではなく)内部ネットワークからそれらを実行できるようにしたいと考えています。
クライアントの内部ネットワークでは、(a)独自のデータベースへの書き込みアクセスを許可していません。また、(b)中間SQLサーバーをセットアップすることもできません(つまり、ストアドプロシージャやその他のデータクリーニングをセットアップできません)。
SQLには、row_number()over(col1、col2によるパーティション)、 col1によるグループ化、cube | rollupを使用したcol2 、および/または(複数の)ピボットの複数のインスタンスが含まれています。
これもできますか?私が読んだすべてのことは、これはストアドプロシージャを介してのみ実行可能であり、最初にプロプライエタリデータベースからデータをプルする必要があることを示しているようです。
以下は、クエリの1つを取り除いたバージョンです(たとえば、機能に直接関連しないJOIN、WHERE句、および5ダースの列が削除されています)...
select sum(programID)
, sum([a.Asian]) as [Episodes - Asian], sum([b.Asian]) as [Eps w/ Next Svc - Asian], sum([c.Asian])/sum([b.Asian]) as [Avg Days to Next Svc - Asian]
, etc... (repeats for each ethnicity)
from (
select programID, 'a.' + ethnicity as ethnicityA, 'b.' + ethnicity as ethnicityB, 'c.' + ethnicity as ethnicityC
, count(*) as episodes, count(daysToNextService) as episodesWithNextService, sum(daysToNextService) as daysToNextService
from (
select programID, ethnicity, datediff(dateOfDischarge, nextDateOfService) as daysToNextService from (
select t1.userID, t1.programID, t1.ethnicity, t1.dateOfDischarge, t1.dateOfService, min(t2.dateOfService) as nextDateOfService
from TABLE1 as t1 left join TABLE1 as t2
on datediff(d, t1.dateOfService, t2.dateOfService) between 1 and 31 and t1.userID = t2.userID
group by t1.userID, t1.programID, t1.ethnicity, t1.dateOfDischarge, t1.dateOfService
) as a
) as a
group by programID
) as a
pivot (
max(episodes) for ethnicityA in ([A.Asian],[A.Black],[A.Hispanic],[A.Native American],[A.Native Hawaiian/ Pacific Isl.],[A.White],[A.Unknown])
) as pA
pivot (
max(episodesWithNextService) for ethnicityB in ([B.Asian],[B.Black],[B.Hispanic],[B.Native American],[B.Native Hawaiian/ Pacific Isl.],[B.White],[B.Unknown])
) as pB
pivot (
max(daysToNextService) for ethnicityC in ([C.Asian],[C.Black],[C.Hispanic],[C.Native American],[C.Native Hawaiian/ Pacific Isl.],[C.White],[C.Unknown])
) as pC
group by programID with rollup
Sooooooo....このようなものをCrystalReportsXIに変換することもできますか?
ありがとう!