Biztalk Musings

Biztalk and its use in Healthcare

Export to Excel from SQL

clock February 16, 2012 21:05 by author btsguy

alter procedure usp_Export2ExcelVS
(
@db_name varchar(100),
@table_name varchar(100), 
@file_name varchar(100)
)
as

--Generate column names as a recordset
declare @columns varchar(8000), @sql varchar(8000), @data_file varchar(100)
select
@columns=coalesce(@columns+',','')+column_name
from
information_schema.columns
where
table_name=@table_name

select @columns = '''''' + replace(@columns,',',''''',''''') + ''''''

print @columns
--Create a dummy file to have actual data
select @data_file=substring(@file_name,1,len(@file_name)-charindex('\',reverse(@file_name)))+'\data_file.xls'

print @data_file

--Generate column names in the passed EXCEL file
set @sql='exec master..xp_cmdshell ''bcp " select '+@columns+' as t" queryout "'+@file_name+'" -c -T -S "<server>"'''
exec(@sql)

--Generate data in the dummy file
set @sql='exec master..xp_cmdshell ''bcp "select * from '+@db_name+'..'+@table_name+'" queryout "'+@data_file+'" -c -T -S "<server>"'''
exec(@sql)

--Copy dummy file to passed EXCEL file
set @sql= 'exec master..xp_cmdshell ''type '+@data_file+' >> "'+@file_name+'"'''
exec(@sql)

--Delete dummy file
set @sql= 'exec master..xp_cmdshell ''del '+@data_file+''''
exec(@sql)
GO

/*
exec usp_Export2ExcelVS 'Northwind','OrderHistory','c:\temp\excel.xlsx'
*/



ASP.NET MVC4 (Beta) Released

clock February 16, 2012 16:26 by author btsguy

http://www.asp.net/whitepapers/mvc4-release-notes



jQuery vs KendoUI

clock February 14, 2012 18:26 by author btsguy

http://jqueryuivskendoui.com/



WCF Installation Steps

clock February 8, 2012 20:38 by author btsguy

http://msdn.microsoft.com/en-us/library/aa751792.aspx

http://msdn.microsoft.com/en-us/library/ms752241.aspx



SQL XP FileExists

clock February 7, 2012 21:52 by author btsguy

http://www.mssqltips.com/sqlservertip/1272/file-validation-in-sql-server-with-xpfileexist-stored-procedure/



Embed Image in Email

clock February 7, 2012 21:47 by author btsguy

http://www.codeproject.com/Tips/326346/How-to-embed-a-image-in-email-body?utm_source=twitterfeed&utm_medium=twitter



Create Sample Db in SQL

clock February 7, 2012 21:46 by author btsguy

http://www.codeproject.com/Tips/326527/Create-a-sample-SQL-database-in-less-than-2-minute?utm_source=twitterfeed&utm_medium=twitter



Whats new in Powershell 3.0?

clock February 2, 2012 20:12 by author btsguy

http://social.technet.microsoft.com/wiki/contents/articles/4788.powershell-v3-tips-and-tricks-what-s-new-in-v3.aspxhttp://social.technet.microsoft.com/wiki/contents/articles/4788.powershell-v3-tips-and-tricks-what-s-new-in-v3.aspx



How to Recover Single Sign On

clock February 2, 2012 16:54 by author btsguy

http://msdn.microsoft.com/en-us/library/aa561150%28v=bts.10%29.aspx



SQL Performance

clock February 2, 2012 16:32 by author btsguy

http://support.microsoft.com/kb/224587/en-gb