[SQL][sybase]use SQL server OPEN QUERY Sybase with parameter

 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)

沒有留言:

張貼留言

[DataSet Bug]無法啟用條件約束。一或多個資料列的值違反非 Null、唯一或外部索引鍵條件約束

在使用TableAdapter作Query時發生 1. 原因為有些資料欄位Query出來後為null值 但是該欄位在dbDataSet的屬性AllowDBNull為False 因此把該欄位(或乾脆把全部欄位屬性AllowDBNull改為True 2. maxLength 檢...