私は最後のステートメントとは別に、すべてのものを順番に取得しています。ここでは2つの基準を持つステートメントSQL
私の検索条件をさらに絞り込んで、agencyprofilesetupcomplete内のレコードの1つが0の場合は、agencyprofilecreateddateの日付が今日の日付よりも90日少ないかどうかを調べます。ifそれらの結果も含めたいと思っています。
select
distinct agencyprofilename,
(select
top 1 agencypayperiodfinalisestate
from
agencypayperiod as app
where
app.agencyprofileid = ap.agencyprofileid
order by
agencypayperiodpaydate)as 'Pay Period Finalise State',
agencyprofilecreateddate, agencyprofilesetupcomplete,
agencyemployertaxoffice
from
Agencyprofile as ap
left join
agencypayperiod as app on ap.agencyprofileid = app.agencyprofileid
left outer join
agencyemployer as ae on ap.agencyemployerid = ae.agencyemployerid
where agencypayperiodfinalisestate <>0
and agencyemployertaxoffice is not null
and agencyemployertaxoffice <>''
or (agencyprofilesetupcomplete = 0 and agencyprofilecreateddate >=
(GetDate()-90))
order by agencyprofilename
知りたい場合は、Microsoft SQL Serverも使用しています。
このクエリでエラーが発生しましたか。 – Shammas
あなたはあなたの基準を正しく読んでいるならば、あなたは 'agencyprofilecreateddate <(GetDate() - 90')を望んでいると思うでしょう –
あなたの質問は何ですか?あなたが望まないデータを取得していますか、あるいはデータを取得していませんか? – Caleth