Solved

creating html table from Sql server Stored procedure

Posted on 2010-09-14
4
465 Views
Last Modified: 2012-05-10
I have a sp in sql server2005 with reult a table.
I want to populate this table into html table.
0
Comment
Question by:petersti
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 33675571
0
 
LVL 41

Expert Comment

by:ralmada
ID: 33675605
another example here. Look for example C.
http://msdn.microsoft.com/en-us/library/ms190307.aspx 
0
 
LVL 2

Expert Comment

by:JimyLee
ID: 33675617
Which server language are you using to read from the database and write the web pages?

Once you have read the results into something, like VBScript or PHP, then you can loop through your array and write an html table row for each record from you sp.

For example, the following loop would write the contents of an array in VBScript:

response.write "<html><body><table>"
   for count = 0 to ubound(objMyArray,2)
        response.write "<tr><td>" & objMyArray(1,count) & "</td><td>" & objMyArray(2,count) & "</td><td>" & objMyArray(3,count) & "</td></tr>"  
    next
response.write "</table></body></html>"
0
 
LVL 4

Expert Comment

by:parthmalhan
ID: 33679854
try the following code:

set nocount on
go
create table #t(col1 varchar(15) null,col2 varchar(15) null,col3 varchar(15) null)
go
insert into #t values('James','123','321')
insert into #t values('Bond','123','321')
insert into #t values('007','123','321')
select '<table border="1"><tr><th>col1</th><th>col2</th><th>col3</th></tr>'
select '<tr><td>'+ltrim(rtrim(col1)),'</td><td>'+col2,'</td><td>'+col3+'</td><tr>' from #t
drop table #t

its output will be like this:


------------------------------------------------------------------
<table border="1"><tr><th>col1</th><th>col2</th><th>col3</th></tr>

                                                 
----------------------- ------------------------ ---------------------------------
<tr><td>James           </td><td>123             </td><td>321</td><tr>
<tr><td>Bond            </td><td>123             </td><td>321</td><tr>
<tr><td>007             </td><td>123             </td><td>321</td><tr>


Remove the dotted lines,Copy rest in the notepad and save it as '.html'
thats it.

NOTE:
1.Select Results to text option Button and after that run the above query.
2.There will be only two lines always.No matter the rows a table/Query contains.

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question