91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎樣從生產數據庫中獲得想要的查詢語句,把結果集批量插入到磁盤txt文件中

發布時間:2020-08-21 17:18:47 來源:網絡 閱讀:2485 作者:51GT 欄目:關系型數據庫

第一步:建立存儲過程

      實現傳入參數,生成結果到磁盤的txt文件中;


USE [XXXXX]

GO

/****** Object:  StoredProcedure [dbo].[Proc_sql_to_file]    Script Date: 2018/5/13 15:47:10 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author:<Author,,Name>

-- Create date: <Create Date,,>

-- Description:<Description,華為廠商為了獲取本系統數據寫此存儲過程,調用此過程生成txt文件保存到服務器,然后ftp到華為,>

-- =============================================


ALTER PROCEDURE [dbo].[Proc_sql_to_file](

@servername varchar(50),--服務器名

@username varchar(50),--用戶名,如果用NT驗證方式,則為空''

@password varchar(50) ,--密碼

@sql_query varchar(2000) , --SQL查詢語句,有字符條件時用單引號

@filePath_name varchar(1000), --導出路徑和文件名

@date datetime --保存文件時的生成日期戳

)AS

DECLARE @sql varchar(8000)

SET @sql='bcp "'+@sql_query + '" queryout '+' "'+@filePath_name+'_'+

convert(varchar(10),@date,21)+'.txt " /t "," /w'

+' /S '+@servername

+CASE WHEN ISNULL(@username,'')='' THEN '' ELSE ' /U '+@username END

+' /P '+ISNULL(@password,'')


select @sql

EXEC master..xp_cmdshell @sql

IF @@Error<>0 BEGIN

print '生成文件時出錯了,請查看!'+@@Error

END


第二步:數據庫中新建任務計劃;


use XXXXX;---數據庫名稱

go

if exists(select 1 from sysobjects where name='temp11')

drop table temp11;

if exists(select 1 from sysobjects where name='temp12')

drop table temp12;

go

go

declare @date1 datetime;set @date1 =CONVERT(varchar(10),Getdate(), 21);


--華為采購數量時間為當天;

select CONVERT(varchar(100), GETDATE(), 102)+'入庫串碼' 手機串碼,'數量' 數量,'倉庫' 倉庫 into temp11

union all

select 

'   '+t4.FSERIALNO,convert(varchar,1) Fqty,tl.fname FstockName

from T_STK_INSTOCK  t1

inner join T_STK_INSTOCKentry t2 on t1.fid=t2.fid

inner join  T_STK_INSTOCKENTRY_F t3 on t2.fid=t3.fid

left join T_STK_INSTOCKSERIAL t4 on t3.FENTRYID=t4.FENTRYID

inner join t_bd_material_l t6 on t2.FMATERIALID=t6.FMATERIALID and t6.FLOCALEID=2052

left join T_BD_STOCK_L tl on t2.FSTOCKID=tl.FSTOCKID and tl.FLOCALEID=2052

inner join ( select distinct m.FMATERIALID,m.FCATEGORYID,w.fname from T_BD_MATERIALBASE m

 join T_BD_MATERIALCATEGORY_L w on m.FCATEGORYID=w.FCATEGORYID

  ) u on t6.FMATERIALID=u.FMATERIALID

where u.fname like '%手機%'  and t6.fname like '%華為%'

and convert(varchar(10),t1.FDATE,21)=convert(varchar(10),getdate(),21)

--庫存數量

select CONVERT(varchar(100), GETDATE(), 102)+'在庫串碼' 手機串碼,'數量' 數量,'倉庫' 倉庫 into temp12

union all

SELECT   FNUMBER,convert(varchar,1) Fqty,ckl.FNAME FstockName  

 FROM (select FNUMBER,FSERIALID,FMATERIALID from V_BD_OVERASERIALVIEW where FSERIALID>1 and  FDOCUMENTSTATUS = 'C' AND FFORBIDSTATUS = 'A') t0 

  INNER   JOIN (select FSERIALID from V_BD_OVERASERIALVIEW_L where FSERIALID>1  AND FLocaleId = 2052) t0_L ON (t0.FSERIALID = t0_L.FSERIALID)

  INNER    JOIN (select FSERIALID From V_BD_OVERASERIALORGVIEW where FSERIALID>1  and  FSTOCKSTATUS = 1 ) uu on uu.FSERIALID=t0.FSERIALID

  inner   join (select FMATERIALID,FNAME FSPMC From t_bd_material_l where FMATERIALID>1 and FLocaleId = 2052) tll on t0.FMATERIALID =tll.FMATERIALID 

  INNER   join (select FCATEGORYID,FMATERIALID From T_BD_MATERIALBASE where FCATEGORYID>1 and FCATEGORYID ='2092334' ) m on t0.FMATERIALID=m.FMATERIALID

  left   join (SELECT FSERIALID,MIN(FINPUTDATE) FINPUTDATE  FROM (select a.FSERIALID FSERIALID,case when b.FINPUTDATE not like '' then b.FINPUTDATE else   a.FBILLDATE

end FINPUTDATE from (select FSERIALID,FBILLDATE  From T_BD_SERIALBILLTRACE_e where FSERIALID>1 ) a  INNER   join (select FSERIALID,FINPUTDATE From T_BD_SERIALMASTEROTHER where FSERIALID>1) b on a.FSERIALID=b.FSERIALID ) a GROUP BY FSERIALID) b on t0.fserialid=b.FSERIALID

INNER   JOIN (select FSERIALID,FBILLTRACEID,FINVID from T_BD_SERIALBILLTRACE  where FBILLTRACEID>1 and FSERIALID>1 ) t5 ON T0.FSERIALID  = t5.FSERIALID  AND t5.FBILLTRACEID = (SELECT top 1 EE.FBILLTRACEID AS FBILLTRACEID FROM T_BD_SERIALBILLTRACE  EE WHERE T0.FSERIALID = EE.FSERIALID and( FINVID is not null and FINVID <> '' ) order by FBILLTRACEID desc)

 inner   join (select fid,FSTOCKID,FSTOCKSTATUSID from T_STK_INVENTORY where   FSTOCKSTATUSID=10000 and FOBJECTTYPEID= 'STK_Inventory'  and FKEEPERTYPEID='BD_KeeperOrg'and FOWNERTYPEID='BD_OwnerOrg' and FISEFFECTIVED=1 and FBASEQTY<>0) inv on inv.fid=t5.FINVID 

 inner   join (select FSTOCKID,FNAME from T_BD_STOCK_L where FSTOCKID>1 and FLocaleId = 2052   ) ckl on inv.FSTOCKID=ckl.FSTOCKID 

 where FSPMC like '%華為%'

option(maxdop 0)

 EXEC XXXXX..Proc_sql_to_file 'DESKTOP-89KSR2K','sa','dingweitao','select * from XXXXX.dbo.temp11','d:\k3cloud_Instock\k3cloud_Instock',@date1

  EXEC XXXXX..Proc_sql_to_file 'DESKTOP-89KSR2K','sa','dingweitao','select * from XXXXX.dbo.temp12','d:\k3cloud_Inventory\k3cloud_Inventory',@date1

go

drop table temp11,temp12

go



最終每天會更新數據到文件中;



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

将乐县| 彭山县| 儋州市| 古田县| 黄龙县| 阳东县| 方城县| 阿尔山市| 大竹县| 泰宁县| 轮台县| 佛冈县| 广东省| 洪洞县| 浪卡子县| 河间市| 孟津县| 灵台县| 太保市| 宁安市| 鹰潭市| 甘谷县| 乐都县| 象山县| 吴忠市| 麦盖提县| 库伦旗| 房产| 东丰县| 新绛县| 淳化县| 水城县| 泰和县| 城步| 龙川县| 通榆县| 于都县| 定边县| 诏安县| 三原县| 耿马|