Solved

creating html table from Sql server Stored procedure

Posted on 2010-09-14
4
477 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
[X]
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
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
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 video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

740 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