Is it possible to connect an Access form to a SQL Server view

前端 未结 4 1186
感情败类
感情败类 2021-01-26 11:15

I\'m migrating an Access DB to SQL Server and everything is slowly coming along but Im not sure how to connect the Access forms to the SQL Server views.

So far I have al

4条回答
  •  梦毁少年i
    2021-01-26 12:01

    You can't reference the Access form in a SQL View directly. You will need to rethink the logic in this. You could either create a number of Views with the appropriate values hard-coded (inadvisable) or convert the View to a Stored Procedure and pass the value in as a parameter.

    For example (assuming the parameter is a string):

        create proc s_MyStoredProc
    
        @Location varchar(50)
    
        AS
        BEGIN
         SELECT 
          [AcuteHospitals].[NHSN_ID], 
          [AcuteHospitals].[HospitalName], 
          [Location_LOV].[Description] AS Location, 
          Sum([RateTable_CLABData].[clabcount]) AS [Number of CLABSI], 
          Sum([RateTable_CLABData].[numcldays]) AS [Central Line Days], 
          [RateTable_CLABData].[CLAB_Mean] AS [National Average]
       FROM 
          (([AcuteHospitals] 
             LEFT JOIN [RateTable_CLABData] 
             ON [AcuteHospitals].[NHSN_ID] = [RateTable_CLABData].[orgID]) 
             LEFT JOIN [Location_LOV] 
             ON [RateTable_CLABData].[loccdc] = [Location_LOV].[CDCLoc]) 
             LEFT JOIN [SummaryYQ_LOV] 
             ON [RateTable_CLABData].[summaryYQ] = [SummaryYQ_LOV].[StartDate]
       WHERE ((([SummaryYQ_LOV].[SummaryYQ]) = @Location ))
       GROUP BY 
          [AcuteHospitals].[NHSN_ID], 
          [AcuteHospitals].[HospitalName], 
          [Location_LOV].[Description], 
          [RateTable_CLABData].[CLAB_Mean], 
          [RateTable_CLABData].[loccdc]
       HAVING ((([RateTable_CLABData].[loccdc]) NOT LIKE '%ped%'))
       ORDER BY [AcuteHospitals].[HospitalName], [RateTable_CLABData].[loccdc]
    
    END
    

提交回复
热议问题