creating html table from Sql server Stored procedure

Posted on 2010-09-14
Medium Priority
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.
Question by:petersti
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 41

Accepted Solution

ralmada earned 2000 total points
ID: 33675571
LVL 41

Expert Comment

ID: 33675605
another example here. Look for example C.

Expert Comment

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>"  
response.write "</table></body></html>"

Expert Comment

ID: 33679854
try the following code:

set nocount on
create table #t(col1 varchar(15) null,col2 varchar(15) null,col3 varchar(15) null)
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.

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.


Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

762 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