Solved

creating html table from Sql server Stored procedure

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 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