rendering html from sql server
I can't think of a single legitimate reason for ever doing this, but here's my latest post on rendering html from within a repl, this time from the SQL Server management studio (formerly known as Query Analyzer) . Previous posts show how to do this in irb (ruby) and in PowerShell.
EDIT PROC usp_Show_HTML (@html varchar(8000))
AS
DECLARE @ie int
EXEC sp_OACreate 'InternetExplorer.Application',@ie OUT
EXEC sp_OASetProperty @ie,'menubar',0
EXEC sp_OASetProperty @ie,'toolbar',0
EXEC sp_OASetProperty @ie,'statusbar',0
EXEC sp_OAMethod @ie,'navigate',null,'about:blank'
DECLARE @doc int
EXEC sp_OAGetProperty @ie,'document',@doc OUT
EXEC sp_OAMethod @doc,'write',null,@html
EXEC sp_OASetProperty @ie, 'Visible', 'true'
This only works if you are connecting to a SQL Server running on localhhost, and if the SQL Server service is set to run under the 'Local System Account' with the 'Allow service to interact with desktop' checkbox ticked.
To use:
SET NOCOUNT ON
CREATE TABLE #t(output varchar(256))
INSERT INTO #t
EXEC xp_cmdshell 'SET'
DECLARE c CURSOR FAST_FORWARD FOR SELECT output FROM #t WHERE output IS NOT NULL
DECLARE @output varchar(256)
DECLARE @html varchar(8000)
SET @html='<table>'
OPEN c
FETCH NEXT FROM c INTO @output
WHILE @@FETCH_STATUS>-1 BEGIN
SET @html=@html+'<TR><TD>'+REPLACE(@output,'=','</TD><TD>')+'</TD></TR>'
FETCH NEXT FROM c INTO @output
END
CLOSE c
DEALLOCATE c
SET @html=@html+'</TABLE>'
EXEC usp_Show_HTML @html
DROP TABLE #t