脱裤DB实验

脱裤DB实验

HashFlare

天朝同胞可以看优酷

/****** Script for TEST BY ly ******/

首先我们先看下原始数据

SELECT * FROM [GroupData1].[dbo].[Group2]

然后我们筛选出email

SELECT t.QUNNum AS QUNNum,STUFF(
(SELECT ‘@qq.com,’ + CAST(s.QQNum as varchar(100))
FROM [GroupData1].[dbo].[Group2] s
WHERE s.QUNNum=t.QUNNum
FOR XML PATH(”)),1,8,”) + ‘@qq.com’ AS Email
FROM [GroupData1].[dbo].[Group2] t
group by t.QUNNum;

最后用bcp命令生成excel

bcp “SELECT t.QUNNum AS QUNNum,STUFF((SELECT ‘@qq.com,’ + CAST(s.QQNum as varchar(100)) FROM [GroupData1].[dbo].[Group2] s WHERE s.QUNNum=t.QUNNum FOR XML PATH(”)),1,8,”) + ‘@qq.com’ AS Email FROM [GroupData1].[dbo].[Group2] t group by t.QUNNum” queryout Email.xls -c -T -U ‘sa’ -P ‘123456’ -S localhost\sqlexpress

其实上面没有过滤掉重复的Email,稍微改下就可以了,自己动脑吧

友荐云推荐

SIMILAR ARTICLES

0 305

0 443