This is the OutXLS function.....................
*************************************************
sub outxls(sql,outfile)
Response.ContentType = "application/vnd.ms-excel"
response.write "<table BORDER=1>"
outstr=""
for Each rf In rs.Fields
outstr = outstr & "<TD NOWRAP=TRUE BGCOLOR=#DDDDDD><B>" & rf.name & "</B></TD>"
Next
response.Write "<tr>" & outstr & "</tr>"
' outstr=""
' for Each rf In rs.Fields
' outstr = outstr & "<TD NOWRAP=TRUE>" & rf.type & "</TD>"
' Next
' response.Write "<tr>" & outstr & "</tr>"
While not rs.eof
outstr=""
For Each rf In rs.Fields
tmp = rs(rf.Name)
If rf.type = "5" then
outstr = outstr & "<TD NOWRAP=TRUE>" & tmp & "</TD>"
Else
outstr = outstr & "<TD NOWRAP=TRUE> " & tmp & "</TD>"
End If
Next
response.Write "<tr>" & outstr & "</tr>"
rs.MoveNext
Wend
rs.close
set rs = nothing
response.write "</table>"
end sub
ASKER
<!--#include file="COMMON.INC"-->
<!--#include file="SESSION.INC"-->
<!--#include file="navbarall.inc"-->
<%
'printSQL = -1
st = timer
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdTableDirect = &H0200
Const adUseClient = 3
Const adCmdText = &H0001
server.scriptTimeout = 3600
Session.Timeout = 60
DIM SLM
SLM = REQUEST("SLM")
NAM = REQUEST("NAM")
If len(SLM)<>4 AND len(SLM)<>6 Then
SLM = ""
End If
If len(SLM) = 6 Then
LTR = mid(SLM,6,1)
SLM = mid(SLM,1,4)
End If
strDB = SESSION("STRDB")
Set con = CreateObject("ADODB.Connection")
con.Open strDB
Set rs = CreateObject("ADODB.Recordset")
If printSQL Then response.write "ORA_SLMS_ALL=" & SESSION("ORA_SLMS_ALL") & "<HR>" End If
SQL = "SELECT TO_CHAR(ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(SYSDATE,'MON-YYYY'),'MON-YYYY'),'YEAR'),-48),'YYYY') START_YEAR FROM DUAL"
If printSQL Then Response.Write SQL & "<HR>" End If
Set rs = con.Execute(SQL)
START_YEAR = RS("START_YEAR") - 1
SQL = "SELECT TO_CHAR(SYSDATE,'MM/DD/YYYY') TODAY FROM DUAL"
If printSQL Then Response.Write SQL & "<HR>" End If
Set rs = con.Execute(SQL)
TODAY = RS("TODAY")
CURRENT_DAY = cint(MID(TODAY,4,2)) - 1
CURRENT_MONTH = cint(MID(TODAY,1,2))
SQL = "SELECT TO_CHAR(LAST_DAY(SYSDATE),'MM/DD/YYYY') LAST_DAY FROM DUAL"
If printSQL Then Response.Write SQL & "<HR>" End If
Set rs = con.Execute(SQL)
LAST_DAY = cint(mid(RS("LAST_DAY"),4,2))
If printSQL Then Response.Write "START_YEAR=" & START_YEAR & " TODAY=" & TODAY & " CURRENT_DAY=" & CURRENT_DAY & " LAST_DAY=" & LAST_DAY & "<HR>" End If
If printSQL then SESSION("TERRITORY") = "" End If
' SQL BELOW returns Territory Number & Name
If SESSION("TERRITORY") = "" Then
SQL = "SELECT DISTINCT TERRITORY, SUBSTR(JRS.NAME,1,LEAST(INSTR(JRS.NAME||'-','-')-1,25)) NAME FROM APPS.WEB_SALES_HISTORY_SLM_MV WSS, " & _
"AR.RA_TERRITORIES RT, AR.RA_SALESREP_TERRITORIES RST, JTF.JTF_RS_SALESREPS JRS " & _
"WHERE WSS.TERRITORY=RT.SEGMENT1 " & _
"AND RT.TERRITORY_ID=RST.TERRITORY_ID " & _
"AND RST.SALESREP_ID=JRS.SALESREP_ID " & _
"AND RST.END_DATE_ACTIVE IS NULL "
If SESSION("USER") <> "TERRITORYSALES" Then
SQL = SQL & "AND RT.SEGMENT1 IN (" & session("ORA_SLMS") & ") "
End If
SQL = SQL & "AND RT.SEGMENT2='ALL' " & _
"ORDER BY TERRITORY"
If printSQL Then Response.Write SQL & "<HR>" End If
Set rs = con.Execute(SQL)
Do While Not rs.EOF
SLM_CHECK = rs("TERRITORY")
If SLM_OK(SLM_CHECK) Then
If instr(LOADED,"/" & SLM_CHECK & "/") = 0 Then
inBuffer = inBuffer + "<SLMS><SLM>" & rs("TERRITORY") & "</SLM><NAM>" & clean(rs("NAME")) & "</NAM></SLMS>"
LOADED = LOADED & "/" & SLM_CHECK & "/"
End If
If printSQL Then response.write "SLM_CHECK=" & SLM_CHECK & "<HR>" End IF
End If
rs.MoveNext
Loop
' SQL BELOW returns Territory Number & Letter_Code & Name
SQL = "SELECT DISTINCT TERRITORY, LETTER_CODE, SUBSTR(JRS.NAME,1,LEAST(INSTR(JRS.NAME||'-','-')-1,25)) NAME FROM APPS.WEB_SALES_HISTORY_SLM_MV WSS, " & _
"AR.RA_TERRITORIES RT, AR.RA_SALESREP_TERRITORIES RST, JTF.JTF_RS_SALESREPS JRS " & _
"WHERE WSS.TERRITORY=RT.SEGMENT1 " & _
"AND RT.TERRITORY_ID=RST.TERRITORY_ID " & _
"AND RST.SALESREP_ID=JRS.SALESREP_ID " & _
"AND RST.END_DATE_ACTIVE IS NULL " & _
"AND RT.SEGMENT1 IN (" & session("ORA_SLMS") & ") " & _
"AND RT.SEGMENT2='ALL' " & _
"ORDER BY TERRITORY, LETTER_CODE"
If printSQL Then Response.Write SQL & "<HR>" End If
Set rs = con.Execute(SQL)
Do While Not rs.EOF
SLM_CHECK = rs("TERRITORY") & rs("LETTER_CODE")
If SLM_OK(SLM_CHECK) Then
If instr(LOADED,"/" & SLM_CHECK & "/") = 0 Then
inBuffer = inBuffer + "<SLMS><SLM>" & rs("TERRITORY") & "-" & rs("LETTER_CODE") & "</SLM><NAM>" & clean(rs("NAME")) & "</NAM></SLMS>"
LOADED = LOADED & "/" & SLM_CHECK & "/"
End If
' If printSQL Then response.write "SLM_CHECK=" & SLM_CHECK & "<HR>" End IF
End If
rs.MoveNext
Loop
SESSION("TERRITORY") = inBuffer
Else
Inbuffer = SESSION("TERRITORY")
End If
'If printSQL Then Response.Write inbuffer & "<HR>" End If
If SLM<>"" Then
SQL = SQL & " AND TERRITORY='" & SLM & "'"
End If
If LTR <> "" Then
SQL = SQL & " AND LETTER_CODE='" & LTR & "'"
End If
If SLM<>"" Then
SQL = "SELECT " &_
" PARTY_NAME, CITY, STATE, POSTAL_CODE, TERRITORY, LETTER_CODE " &_
" MONTH_N, YEAR_N, SALES_AMT " &_
" FROM APPS.WEB_CUSTOMER_ADDRESSES_V V, " &_
" XKFI.KFI_CUSTOMER_TERRITORY_HEADER H, " &_
" APPS.WEB_SALES_HISTORY_CUST_MV S " &_
" WHERE V.LOCATION = H.CUSTOMER_SITE_ID " &_
" AND H.TERRITORY = '" & SLM & "'" &_
" AND LETTER_CODE = '" & LTR & "'" &_
" AND H.EFFECTIVE_END_DATE IS NULL " &_
" AND V.SITE_USE_CODE = 'BILL_TO' " &_
" AND V.STATUS = 'A' " &_
" AND V.SITE_STATUS = 'A' " &_
" AND V.ACCT_SITE_STATUS = 'A' " &_
" AND S.CUSTOMER_SITE_ID = V.LOCATION " &_
" AND S.YEAR_N >= 2006 " &_
" AND S.SALES_AMT <> 0 " &_
" ORDER BY POSTAL_CODE " &_
rs.close
rs.CursorLocation = adUseClient
rs.Open SQL, con, adOpenForwardOnly, adLockReadOnly, adCmdText
If rs.RecordCount > 65000 Then
response.write "<H1>" & rs.RecordCount & " Records found<br>Maximum records Exceeded<br>Retry Query with a smaller Ranges</H1>"
response.end
End If
If Not rs.EOF Then
call outxls(sql,outfile)
response.end
Else
Message="No Data Found"
End If
END If
SQL = "INSERT INTO XKFI.WEB_TRACKING (TRACKING_ID, TRACKING_DATE, USER_NAME, TRACKING_ACTION, ATTRIBUTE1,ORG_ID) " & _
"VALUES (XKFI.WEB_TRACKING_S.NEXTVAL,SYSDATE,'" & SESSION("USER") & "','SALES_HISTORY','" & SLM<R & "'," & SESSION("ORG_ID") & ")"
If printSQL then Response.Write SQL & "<HR>" End IF
rs = con.Execute(SQL)
Set rs = Nothing
con.close
Set con = Nothing
inBuffer = "<SALESMAN><NAME>" & SLM & LTR & " - " & NAM & "</NAME>" & inBuffer & TMPA & "</SALESMAN>"
'RESPONSE.WRITE inbuffer
'response.end
dim styleFile
styleFile = Server.MapPath("SLMTEST.XSL")
dim source
set source = Server.CreateObject("Microsoft.XMLDOM")
source.async = false
source.loadXML(inBuffer)
dim style
set style = Server.CreateObject("Microsoft.XMLDOM")
style.async = false
style.load(styleFile)
result = source.transformNode(style)
Response.Write(result)
Private Function SLM_OK(Src)
TMPOK = 0
TMPA = split(REPLACE(MID(SESSION("ORA_SLMS_ALL"),2),"//","/"),"/")
TMPN = UBound(TMPA)
For TMPL = 0 to TMPN - 1
' If printSQL Then RESPONSE.WRITE "SRC = " & SRC & "-" & TMPA(TMPL) & " - " & tmpn & "<HR>" End If
If TMPA(TMPL) = mid(SRC,1,len(TMPA(TMPL))) Then
TMPOK = -1
End If
Next
SLM_OK = TMPOK
End Function
sub outxls(sql,outfile)
Response.ContentType = "application/vnd.ms-excel"
response.write "<table BORDER=1>"
outstr=""
for Each rf In rs.Fields
outstr = outstr & "<TD NOWRAP=TRUE BGCOLOR=#DDDDDD><B>" & rf.name & "</B></TD>"
Next
response.Write "<tr>" & outstr & "</tr>"
' outstr=""
' for Each rf In rs.Fields
' outstr = outstr & "<TD NOWRAP=TRUE>" & rf.type & "</TD>"
' Next
' response.Write "<tr>" & outstr & "</tr>"
While not rs.eof
outstr=""
For Each rf In rs.Fields
tmp = rs(rf.Name)
If rf.type = "5" then
outstr = outstr & "<TD NOWRAP=TRUE>" & tmp & "</TD>"
Else
outstr = outstr & "<TD NOWRAP=TRUE> " & tmp & "</TD>"
End If
Next
response.Write "<tr>" & outstr & "</tr>"
rs.MoveNext
Wend
rs.close
set rs = nothing
response.write "</table>"
end sub
%>
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache"></META>
<META HTTP-EQUIV="Expires" CONTENT="-1"></META>
<title>Territory Detail Extract </title>
</head>
<body>
<BODY onLoad="document.frm.book.focus()">
<table border="0" width=670 cellspacing="0" bgcolor="white" cellpadding="0" align="left">
<FORM id="reporttype" NAME="frm" ACTION="" METHOD="post">
<tr>
</tr>
<tr>
<td> </td>
<tr>
<td>
<tr>
<td><font face="Arial" color="black">Condensed Report<font face="Arial" color="black"> <input type="radio" font face="Arial" name="multiple" value="Condensed" /> Full Report <input type="radio" name="multiple" value ="Full" /> <INPUT TYPE="SUBMIT" VALUE="Generate XLS" size="20"></td>
</tr>
<tr>
<td> </td>
<tr>
<TR><TD COLSPAN=3><HR><TD></TR>
</FORM>
</table>
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
Open in new window