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

溫馨提示×

溫馨提示×

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

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

SQL Server 按照分類輸出Excel

發布時間:2020-04-18 07:11:09 來源:網絡 閱讀:483 作者:想燒炭的人 欄目:系統運維

公司銷售部門要統計業務員的客戶并按照業務員名字輸出Excel,看下面程序

--聲明需要的變量
declare @sql varchar(600),@TypeID varchar(6),@MyName varchar(10)
--每個業務員要有一個序號(數字型)
select @TypeID=min(ID) from A_CUST
select @MyName =EMPLOYEE_NAME from A_CUST where ID=@TypeID
--當存在滿足序號的記錄時進行處理
while exists(select 1 from A_CUST where ID=@TypeID)
begin
--拼湊需要執行的語句
set @sql='bcp "select * from (select'+'''CUSTOMER_CODE'''+' AS 客戶編碼,'+'''CUSTOMER_NAME'''+' AS 客戶名稱,'+'''CUSTOMER_FULL_NAME'''+' AS 客戶全稱,'
+'''EMPLOYEE_CODE'''+' AS 工號,'+'''EMPLOYEE_NAME'''+' AS 姓名,'+'''ADDRESS'''+' AS 地址,'+'''TELEPHONE'''+' AS 電話,'+'''CONTACT'''+' AS 聯系人'--在xls文件中顯示列名
set @sql=@sql+' union all select CUSTOMER_CODE,CUSTOMER_NAME,CUSTOMER_FULL_NAME,EMPLOYEE_CODE,EMPLOYEE_NAME,ADDRESS,TELEPHONE,CONTACT from A_CUST where ID='+cast(@TypeID as varchar(10))+')a" queryout "D:\customer\'+cast(@MyName as varchar(10))+'.xls" -c -q -S"127.0.0.1" -U"sa" -P"密碼" -d"數據庫名稱"'--查詢滿足條件的記錄并保存到xls文件中
--使用xp_cmdshell系統存儲過程執行拼湊好的語句(需要使用高級選項開關預先開啟cmdshell組件)
exec master..xp_cmdshell @sql
--獲得下一個業務員的序號(序號是不連續的)
select @TypeID=isnull(min(ID),@TypeID+1) from A_CUST where ID>=@TypeID+1
select @MyName =EMPLOYEE_NAME from A_CUST where ID=@TypeID
end

下面的程序是根據各表關聯生成的視圖
drop view A_CUST
create view A_CUST as select CUSTOMER_CODE,CUSTOMER_NAME,CUSTOMER_FULL_NAME,EMPLOYEE_CODE,EMPLOYEE_NAME,d.ADDRESS,d.TELEPHONE,e.CONTACT,A_C.ID from CUSTOMER a
left join CUSTOMER_SALES b ON a.CUSTOMER_BUSINESS_ID = b.CUSTOMER_ID
left join EMPLOYEE c ON b.Owner_Emp = c.EMPLOYEE_ID
left join A_C ON c.EMPLOYEE_CODE = A_C.GH
left join CUSTOMER_ADDRESS d ON b.CUSTOMER_BUSINESS_ID = d.CUSTOMER_BUSINESS_ID
left join CUSTOMER_CONTACT e ON b.CUSTOMER_BUSINESS_ID = e.CUSTOMER_BUSINESS_ID
where a.ApproveStatus = 'Y'

insert into A_C(GH) select EMPLOYEE_CODE from EMPLOYEE

select * from A_C

select from A_CUST where ADDRESS is not null
select
from CUSTOMER where CUSTOMER_CODE = '0080'
select *from CUSTOMER_SALES where CUSTOMER_ID = 'F16DD932-0155-4A9A-4FE9-13BF5CF9277D'

向AI問一下細節

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

AI

凤阳县| 娄底市| 望江县| 重庆市| 云阳县| 新余市| 芮城县| 呼图壁县| 梁山县| 和林格尔县| 隆昌县| 遂平县| 游戏| 孟津县| 兴仁县| 互助| 甘泉县| 克东县| 夏津县| 信丰县| 东台市| 嵊泗县| 集贤县| 毕节市| 连平县| 弋阳县| 瓦房店市| 金秀| 永德县| 安化县| 上杭县| 深水埗区| 丘北县| 长垣县| 台南县| 吴川市| 呼和浩特市| 铜陵市| 聊城市| 黑水县| 屏东市|