28,405
社区成员
发帖
与我相关
我的任务
分享create table cs(if_xh int identity(1,1) primary key,
f_uesr nvarchar(10),
f_bmid nvarchar(10),
f_ip nvarchar(30),
f_bhrq datetime,
a real,
b real,
c real,
d real)
insert into cs select '005','0005','127.0.0.1','2009-09-20',2,2,2,2
union all select '0006','0006','127.0.0.5','2009-09-21',2,1,3,5<%Dim SQLServerName,SQLDBUserName,SQLDBPassword,SQLDBName,conn,connstr
SQLServerName = "192.168.0.6"
SQLDBUserName = "sa"
SQLDBPassword = "fiona"
SQLDBName = "test"
on Error resume next
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=sqloledb;user id="&SQLDBUserName&";password="&SQLDBPassword&";initial catalog="&SQLDBName&";data source="&SQLServerName&";"
conn.Open connstr
''-- Check Error Number Start --
if Err.Number<>0 then
response.write(err.description&"<br>Please re-config SQL Server!")
response.End()
end if
on Error Goto 0''--Check End--%>[<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%response.Buffer=true
response.Expires=0 %>
<!--#include file="../../common/menuinc.asp" -->
<!--#include file="../../common/public_function.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
sql="select * into qq from ( select * from (select [f_uesr],[product_code]='a',[qty]=[a] ,[f_bhrq],[f_ip] from cs union all select [f_uesr],[product_code]='b',[qty]=[b] ,[f_bhrq],[f_ip] from cs union all select [f_uesr],[product_code]='c',[qty]=[c] ,[f_bhrq],[f_ip] from cs" &""
sql=sql &" union all select [f_uesr],[product_code]='d',[qty]=[d] ,[f_bhrq],[f_ip] from cs )t )tt order by [product_code]"
conn.execute(sql)
response.Write sql
set rs=server.CreateObject("Adodb.recordset")
sql1="select isnull(product_code,0) as product_code , max(case f_uesr when '0005' then qty else 0 end) huangqi, max(case f_uesr when '0006' then qty else 0 end)huayuan, max(case f_uesr when '0007' then qty else 0 end) qinren from qq where f_uesr='0005' group by isnull(product_code,0)"
set rs=conn.execute(sql1)
if not rs.eof then%>
<table border="1">
<tr>
<td>序号</td>
<td>黄岐</td>
<td>华远</td>
<td>亲人</td>
</tr>
<%do while not rs.eof%>
<tr>
<td><%=rs(0)%></td>
<td><%=rs(1)%> </td>
<td><%=rs(2)%> </td>
<td><%=rs(3)%> </td>
<tr>
<%rs.movenext
loop
rs.close
set rs=nothing
conn.execute("DROP TABLE qq")'将临时表删除
conn.close:set conn=nothing
%>
</table>
<%end if%>
</body>
</html>
<--#include file="cs.asp"-->
<%
set conn=server.CreateObject("adodb.connection")
sql="" ‘你的查询语句
set rs=conn.execute (sql)'执行查询
if not rs.eof then
%>
<table>
<tr>
<td>商品编码</td>
<td>黄岐</td>
<td>华远</td>
<td>亲人</td>
</tr>
<% do while not rs.eof '循环%>
<tr>
<td><%=rs("字段1")%></td>
<td><%=rs("字段2")%></td>
<td><%=rs("字段3")%></td>
<td><%=rs("字段4")%></td>
</tr>
<%
rs.movenext
loop
set rs=nothing
set conn=nothing '如果不再需要数据连接就关掉
end if
%>
</table>