DECLARE @TableName VARCHAR(50);SET @TableName = 'Buzzreader_Data_Union';--系统表syscolumns中xtype = 61表示是日期字段,除了日期字段,其它都可以原样输出--char(9) 水平制表符--char(10) 换行键--char(13) 回车键DECLARE @datastr2 VARCHAR(MAX);SELECT @datastr2 = ISNULL(@datastr2 + ',', '')+ CASE WHEN b.xtype = 61 THEN '[' + b.name + '] AS [' + b.name + ']'ELSE 'replace(replace(replace(replace([' + b.name+ '],''\'',''\\''),CHAR(9),''''),CHAR(10),''''),CHAR(13),'''') AS ['+ b.name + ']'ENDFROM sys.tables aJOIN sys.syscolumns b ON a.object_id = b.idWHERE a.name = @TableName;SET @datastr2 = 'SELECT '+@datastr2 + ' FROM ' + @TableNameEXEC master.dbo.PrintLongText @datastr2EXEC master..xp_cmdshell 'BCP "@datastr2 库名.架构名.表名" queryout 路径\表名.txt -c -t "\t" -T'
1200字范文,内容丰富有趣,写作的好帮手!