SQL view:
SELECT TOP 100 dbo_tbInpatientEpisodes1011.ProviderCode AS FirstProviderCode, dbo_tbInpatientEpisodes1011.CommissionerCode AS FirstCommCode, dbo_tbInpatientEpisodes1011.PointOfDeliveryRS AS FirstPoD, dbo_tbInpatientEpisodes1011.NHSNumber, dbo_tbInpatientEpisodes1011.EpisodeId, dbo_tbInpatientEpisodes1011.AdmissionDate AS FirstAdmitDate, dbo_tbInpatientEpisodes1011.DischargeDate AS FirstDischargeDate, dbo_tbInpatientEpisodes1011.TreatmentSpecialtyCode AS FirstTFC, dbo_tbInpatientEpisodes1011.TreatmentSpecialtyDescription AS FirstTFCDesc, dbo_tbInpatientEpisodes1011.CBSADerivedHRGCode AS FirstHRG, dbo_tbInpatientEpisodes1011.CBSADerivedHRGDescription AS FirstHRGDesc, dbo_tbInpatientEpisodes1011.CBSADerivedDGVPProcedureCode AS FirstPrimOp, dbo_tbInpatientEpisodes1011.CBSADerivedDGVPProcedureName AS FirstPrimOpDesc, dbo_tbIpDiagnosis1011Relational.DiagnosisCode AS FirstICD10, dbo_tbIpDiagnosis1011Relational.DiagnosisDescription AS FirstICD10Desc INTO Admit_Discharge
FROM (dbo_tbInpatientEpisodes1011 INNER JOIN Trust ON dbo_tbInpatientEpisodes1011.ProviderCode = Trust.Trust) LEFT JOIN dbo_tbIpDiagnosis1011Relational ON dbo_tbInpatientEpisodes1011.EpisodeId = dbo_tbIpDiagnosis1011Relational.EpisodeId
WHERE (((dbo_tbInpatientEpisodes1011.CBSADerivedHRGCode) Not Like "NZ*") AND ((dbo_tbIpDiagnosis1011Relational.DiagnosisCode) Not Like "C*" Or (dbo_tbIpDiagnosis1011Relational.DiagnosisCode) Not In ('D037','D038','D039','D04','D040','D041','D042','D043','D044','D045','D046','D047','D048')) AND ((dbo_tbIpDiagnosis1011Relational.DiagnosisOrder)=1) AND ((dbo_tbInpatientEpisodes1011.IsExcluded)=0) AND ((dbo_tbInpatientEpisodes1011.IsDominant)=1) AND ((dbo_tbInpatientEpisodes1011.IsCosted)=1) AND ((dbo_tbInpatientEpisodes1011.DischargeMethodCode) Not Like "2"));