SELECT  (SELECT c_wk AS [市区町村コード] FROM [SENCOM] WHERE [c_id]='18') AS 市区町村コード,
[施設マスタ].[c_skey] AS [施設コード],
[施設マスタ].[c_data] AS [施設名称],
[施設マスタ].[c_ad1] AS [施設所在地_郵便番号],
FORMAT( [KEN_add].[f1], '00000') 
& FORMAT((11 - (((([KEN_add].[f1] \ 10000) * 6) 
  + (([KEN_add].[f1] MOD 10000 \ 1000) * 5)
  + (([KEN_add].[f1] MOD 1000 \ 100) * 4)
  + (([KEN_add].[f1] MOD 100 \ 10) * 3)
  + (([KEN_add].[f1] MOD 10) * 2)) MOD 11)) MOD 10, '0') AS [施設所在地_市区町村コード], 
'0000000' AS [施設所在地_町字コード],     
[KEN_add].[f7] AS [施設所在地_都道府県],
[KEN_add].[f8] AS [施設所在地_市区郡町村名],
'' AS [施設所在地_町字],
IIf([KEN_add].[f3] IS NULL, [施設マスタ].[c_ad2], 
   Trim( IIf(InStr(1, [施設マスタ].[c_ad2], [KEN_add].[f8], 1) > 0, 
    MID(IIf(InStr(1, [施設マスタ].[c_ad2], [KEN_add].[f7], 1) > 0,
       MID([施設マスタ].[c_ad2], LEN([KEN_add].[f7]) + 1),
       [施設マスタ].[c_ad2]), LEN([KEN_add].[f8]) + 1),
    IIf(InStr(1, [施設マスタ].[c_ad2], [KEN_add].[f7], 1) > 0,
       MID([施設マスタ].[c_ad2], LEN([KEN_add].[f7]) + 1),
       [施設マスタ].[c_ad2]))))  AS [施設所在地_番地号表記],
'' AS [施設所在地_方書コード],
'' AS [施設所在地_方書],
'' AS [施設所在地_方書_フリガナ],
Switch([c_scd] = '1', '01',
          [c_scd] = '2', '02',
          [c_scd] = '3', '05',
          [c_scd] = '4', '07',
          [c_scd] = '5', '08',
          [c_scd] = '6', '04',
          [c_scd] = '7', '06',
          [c_scd] = '8', '05', 
          [c_scd] = 'A', '07',
          [c_scd] = 'B', '09'
) AS 施設分類,
TRIM(IIf(InStr(1, [c_seki], ' ',  1) > 0,  
           MID([c_seki], InStr(1, [c_seki], ' ', 1)), 
		           [c_seki])) AS 不在者投票管理者,
'' AS [操作者ID],
'' AS [操作年月日],
'' AS [操作時刻]
FROM ((SELECT * FROM [SENCOM] WHERE [c_id] = '08') AS [施設マスタ]
LEFT JOIN [KEN_add] ON [KEN_add].[f3] = [施設マスタ].[c_ad1])