--创建表,生成html文件内容
create table ##tb(aa varchar(1000))
insert into ##tb
select '<html>'
union all select '<head>'
union all select '<meta http-equiv="Content-Type" content="text/html; charset=gb2312">'
union all select '<title>测试</title>'
union all select '</head>'
union all select '<body>'
union all select '你好,测试中'
union all select '</body>'
union all select '</html>'
--生成test.htm文件
exec master..xp_cmdshell 'bcp ##tb out c:\test.htm /P"" /c'
set @sql='bcp "'+@tbname
+case when @isout=1 then '" out' else '" in' end
+' "'+@filename+'" /c' +' /S"'+@servername
+case when isnull(@username,'')='' then ''
else '" /U"'+@username end
+'" /P"'+isnull(@password,'')+'"'
exec master..xp_cmdshell @sql
go