all groups > inetserver asp db > april 2004 >
You're in the

inetserver asp db

group:

ASP SQL query question


ASP SQL query question Brandon
4/30/2004 5:27:10 AM
inetserver asp db: Greetings,

I have a question about a database query from an asp page. My query is
functional and produces the data that I need; however, one column
contains a numeric value that I need to translate to a name. For
example, the number 1 needs to show up as "VZE" on the loaded web page.
The second column will be the number of tickets, this will not need to
be modified.

This is the current resulting web page:

Vendor Statistics
1 50
2 12
3 8
4 18
5 8
6 5
7 13
8 14
10 3
11 44


This is the code to the query and page layout.

<%@Language=VBScript%>
<!-- #include virtual="adovbs.inc" -->
<HTML><HEAD><META HTTP-EQUIV="Content-Type"
CONTENT="text/html;charset=windows-1252"><TITLE>O/NM</TITLE></HEAD><BODY
[quoted text, click to view]
<%


If IsObject(Session("s1a_conn")) Then
Set conn = Session("s1a_conn")
Else
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "s1a","UID","pwd"
Set Session("s1a_conn") = conn
End If

sql = "SELECT DISTINCT Count(dbo.tbl_common_ticket.vendor_code) AS
ticket_number, dbo.tbl_common_ticket.vendor_code AS vendor_description
FROM dbo.tbl_common_ticket WHERE
(((dbo.tbl_common_ticket.ticket_status_code)=3) AND
((dbo.tbl_common_ticket.work_queue_code)=1)) GROUP BY
dbo.tbl_common_ticket.vendor_code ORDER BY
dbo.tbl_common_ticket.vendor_code "
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, -1, -1
If rs.eof Then
rs.AddNew
End If
Set Session("VZE_O_NM_rs") = rs

%>
<TABLE width=100px border=0px align=left>
<THEAD>
<TH colspan="2">
<font face="courier" size="1" COLOR=#000000>Vendor
Statistics</FONT></TH>
</THEAD>
<TBODY>
<%
On Error Resume Next
rs.MoveFirst
do while Not rs.eof

rs.Fields("vendor_description").Value = vendor_name

select case vendor_name
case 1 vendor_name "VZE"
case else vendor_namee "Other"
End Select

%>
<TR VALIGN=TOP>
</TR>
<TD BORDERCOLOR=#c0c0c0 ALIGN=RIGHT><font face="courier" size="1"
COLOR=#000000><%=Server.HTMLEncode(rs.Fields("vendor_description").Value
)%></font></b></td>
<TD BORDERCOLOR=#c0c0c0 ALIGN=RIGHT><font face="courier" size="1"
COLOR=#000000><%=Server.HTMLEncode(rs.Fields("ticket_number").Value)%></
FONT></TD>
<%
rs.MoveNext
loop
%>
</TBODY>
</TABLE>
</BODY>
</HTML>

Any help in working with this formatting is appreciated.

Thanks,
Brandon

*** Sent via Developersdex http://www.developersdex.com ***
RE: ASP SQL query question John Beschler
4/30/2004 11:46:04 AM
Where are you getting the vendor name from? I see no place where you retrieve the vendor name associated with your vendor number. Is it in another table in the database? If so, you need to include a join to that table in your SQL and select the field that contains vendor name in your SELECT statement

BTW, you will probably see a fairly significant perfomance improvment by putting your SQL i a stored procedure on the server and calling that from the web page

Joh
RE: ASP SQL query question Brandon
5/1/2004 6:16:56 AM
Thanks for your reply.

The vendor name is not a part of any db. I know what the translations
are
supposed to be, so I wanted to use code to translate the vendor number
to a
name before displaying the html.

Unfortunately, stored procedures are not likely to happen. I work for a
large
company and the dba is most likely not going to add procedures for such
a
small project.

Thanks for your help!

Brandon

*** Sent via Developersdex http://www.developersdex.com ***
Re: ASP SQL query question Brandon
5/1/2004 6:57:12 AM

The current web page is:

Vendor Statistics
1 50
2 12
3 8
4 18
5 8
6 5
7 13
8 14
10 3
11 44

And my intention is to turn the left column (1-11) into names that are
not
pulled from a db, rather they are to be translated in the page code. 1
needs
to be VZE, 2 is VZW, and so forth:

Vendor Statistics
VZE 50
VZW 12
AAA 8
BBB 18
CCC 8
DDD 5

etc.

Thanks again.

Brandon

*** Sent via Developersdex http://www.developersdex.com ***
Re: ASP SQL query question Bob Barrows
5/1/2004 9:25:36 AM
[quoted text, click to view]
Please show the intended results.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Re: ASP SQL query question Bob Barrows
5/1/2004 2:10:40 PM
[quoted text, click to view]
So are these names hard-coded somewhere? Or do you intend to hard-code them
into every page that needs to display vendor data (ughhhh!)?

My suggestion is to create a lookup table for these names in your database,
since you say such a lookup table does not already exist.

CREATE TABLE VendorLookup (
vendor_code int,
vendor_description varchar(5) )

Populate it with the vendor codes and names. This will allow you to do the
following in your query (I am going to switch to using table aliases to make
this mess a little more readable - plus I got rid of the unneeded DISTINCT
keyword - the GROUP BY is already guaranteeing distinct rows):

sql = "SELECT Count(t.vendor_code) AS
ticket_number, v.vendor_description
FROM dbo.tbl_common_ticket t INNER JOIN dbo.Vendor_lookup v
ON t.vendor_code = v.vendor_code
WHERE t.ticket_status_code=3 AND t.work_queue_code=1
GROUP BY t.vendor_code, v.vendor_description
ORDER BY t.vendor_code "

If for some strange reason you can't create a lookup table, I suggest
creating an xml file. I am not going to waste time showing you how to do
this unless you reply that you cannot create a lookup table

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Re: ASP SQL query question Brandon
5/2/2004 9:37:20 PM

Thanks for the help, Bob. Your suggestion worked great and I have the
web
page I was aiming to create.

Thanks again,
Brandon

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button