Declare @ps_houses char(2)
Declare @ps_housee char(2)
Declare @ps_dates char(8)
Declare @ps_datee char(8)
set @ps_houses = '01'
set @ps_housee = '31'
set @ps_dates = (select convert(varchar(8),getdate(),112))
set @ps_datee = (select convert(varchar(8),getdate(),112))
Declare @SQL_str varchar(3000)
set @SQL_str='SELECT distinct
trf100s.send_no,
trf100s.tranio_no,
trf100s.raw_no,
trf100s.part_no,
saf300s.send_qty,
saf300s.scan_qty,
saf300s.send_qty - saf300s.scan_qty as no_scanqty ,
baf008.cust_no,
baf008.cust_sname,
trf100.house_no,
baf014.house_name
FROM trf100s
LEFT JOIN trf100 ON trf100s.send_no = trf100.send_no
LEFT JOIN baf008 ON baf008.cust_no = trf100s.cust_no
LEFT JOIN saf300s ON trf100s.send_no = saf300s.send_no
and trf100s.tranio_no = saf300s.tranio_no
and trf100s.part_no = saf300s.part_no
LEFT JOIN baf014 ON trf100.house_no = baf014.house_no
WHERE
saf300s.send_qty - saf300s.scan_qty > 0
and left(saf300s.tranio_no,2) <> ''DI''
and saf300s.barcode_yn = ''Y''
and trf100.house_no between ''' + @ps_houses +''' and ''' +@ps_housee + ''' and convert(char(8),trf100.send_date,112) between '''+ @ps_dates + ''' and '''+ @ps_datee
SET @SQL_str = 'SELECT * into TMP_LHDBTRP100 FROM OpenQuery(LHDB, ''' + REPLACE(rtrim(@SQL_str)+'''', '''', '''''')+ ''')'
EXEC(@SQL_str)
沒有留言:
張貼留言