日期:2014-05-18 浏览次数:20615 次
select Stu_Name+',' from T_Student FOR XML PATH('')
------解决方案--------------------
select (select Stu_Name+',' from T_Student where Stu_Name='xiaoma' FOR XML PATH('')) as TextValue
------解决方案--------------------
很简单,你在SSMS界面里右键,选择“将结果保存到——以文本格式显示结果”,然后执行SQL语句即可,效果如下:
name
--------------------------------------------------
pdf1/dxj_2005_001/14/06/111.pdf
pdf1/dxj_2005_001/14/06/112.pdf
pdf1/dxj_2005_001/14/06/113.pdf
(3 行受影响)
------解决方案--------------------
USE tempdb GO DECLARE @PhysicalPath NVARCHAR(256),@Sql NVARCHAR(MAX) SET @PhysicalPath='H:\aa.txt' DECLARE @tmp TABLE (ID INT IDENTITY(1,1) PRIMARY KEY,Val NVARCHAR(50)) INSERT INTO @tmp (Val) SELECT N'Out' UNION ALL SELECT N'Query Result' UNION ALL SELECT N'Into' UNION ALL SELECT N'Txt File.' SELECT @Sql=ISNULL(@Sql+' ','')+Val FROM @tmp SET @Sql='Exec master.sys.xp_cmdshell ''echo '+@Sql+' >> '+@PhysicalPath+' '',no_output' EXEC (@Sql)