我试图将我的SQL Server查询结果导出到.txt
格式的文件夹中(这是针对自动化作业的)
我知道MySQL中的等效项可用于INTO OUTFILE
。有谁知道在SQL Server 2008 Management Studio中执行此操作的最佳方法?
SELECT DISTINCT RTRIM (s1.SGMNTID) AS 'AccCode',RTRIM (s1.DSCRIPTN) AS 'CodeDesc', CASE
WHEN s1.SGMTNUMB = '1' THEN '1'
WHEN s1.SGMTNUMB = '2' THEN '2'
WHEN s1.SGMTNUMB = '3' THEN '110'
WHEN s1.SGMTNUMB = '4' THEN '4'
WHEN s1.SGMTNUMB = '5' THEN '120'
END AS 'AccountType_id',
CASE WHEN s1.SGMTNUMB = '2'
THEN LEFT(s1.SGMNTID, 2)
ELSE 'DEFAULT'
END AS 'AccGroupName'
FROM GL40200 s1
UNION
SELECT REPLACE ([ACTNUMBR_1]+'-'+ [ACTNUMBR_2]+'-'+ [ACTNUMBR_3]+'-'+[ACTNUMBR_4]+'-'+ [ACTNUMBR_5],' ', '') AS 'AccCode',
'' AS 'CodeDesc',
'0' AS 'AccountType_id',
'Default' AS 'AccGroupName'
FROM GL00100 a
INTO OUTFILE 'C:\Users\srahmani\verian/myfilename.txt'
最佳答案
您可以在SSMS应用(而不是SQL)中执行此操作。在工具栏中选择
查询->结果到->结果到文件
关于sql - SQL Server:将查询导出为.txt文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20620198/