DECLARE @ID char(20) = '3050131019101' select SUBSTRING(TD012,1,8) as 採購日期 ,TD004 as 品號 ,TD005 as 品名 ,TD008 as 數量 ,TD010 as 單價 ,TD014 as 備註 from PURTD where TD004 = @ID and TD018 = 'Y' ORDER BY SUBSTRING(TD012,1,8) DESC select substring(TM002,1,8) as 覈價日期 ,TM004 as 品號 ,TM005 as 品名 ,TM010 as 單價 ,TM012 as 備註 from PURTM where TM004 = @ID and TM011 = 'Y' ORDER BY substring(TM002,1,8) DESC