Solved

creating html table from Sql server Stored procedure

Posted on 2010-09-14
4
472 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

685 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