SELECT 
A1.c_wk AS '市区町村コード',
RIGHT('00000000' + A2.c_skey,8) AS '施設コード',
'1' AS '最新フラグ',
A2.c_data AS '施設名称',
A2.c_ad1 AS '施設所在地_郵便番号',
A2.c_ad2 AS '施設所在地_住所',
RIGHT('00' + A2.c_scd,2) AS '施設分類',
SUBSTRING(A2.c_seki,CHARINDEX(' ',A2.c_seki) +1 ,50) AS '不在者投票管理者',
'0' AS '削除フラグ',
A3.a_jcd AS '操作者ID',
FORMAT(GETDATE(),'yyyy-MM-dd') AS '操作年月日',
LEFT(CAST(GETDATE() AS TIME),8) AS '操作時刻'
FROM (SELECT * FROM sencom WHERE c_id = '18') A1
LEFT JOIN KEN_add2 D ON h1 = c_wk
,(SELECT * FROM sencom WHERE c_id = '08') AS A2
,(SELECT TOP 1 a_jcd FROM senacclog WHERE a_day = Format(GETDATE(),'yyyyMMdd') and a_frm = '帳票メニュー' order by a_time desc) AS A3
