数组到另一个数组 [英] Array into another Array
问题描述
我有一张包含大量数据的表。
目前我的数据是这样的。
userid:1588 | 1 | CR1
用户ID:1588 | 2 | CR2
用户ID:1588 | 1 | CR3
用户ID:1588 | 1 | CR4
用户ID:1588 | 1 | CR5
用户ID:1588 | 2 | CR6
下面的加密格式:
userid | CR1 | CR2 | CR3 | CR4 | CR5 | CR6专栏
1588 | 1 | 2 | 1 | 1 | 1 | 2数据
我已经想出了如何在一些很好的帮助下获取数据。
但它适用于一条记录。
>
我有4342条记录,我怎么能循环下面的例行程序才能获得所有ID。
我尝试了以下但我错过了一些东西。
dim ID,fArray
str =" SELECT userid FROM RESULTED GROUP BY userid"
设置rsx = cn80.Execute (str)
请不要rsx.EOF
ID = rsx(" userid")
fArray = fArray& ; ID&","
rsx.movenext
循环
members = fArray
selections =拆分(成员,,)
为j = 0到UBound(选择)
''在这里运行normail例程在下面
next
<%
dim userid,numbers,cid,sArray
str =" SELECT userid,critic_result,critId from RESULTED WHERE userid =''" &
选择(j)& "''"
设置rs = cn80.Execute(str)
请不要rs.EOF
numbers = rs(" critic_result")
cid = rs(" criticId")
userid = rs(" userid")
sArray = sArray& cr& cid&" ="&数字&","
rs.movenext
循环
''Response.write sArray
''开放记录集
str_sql2 =" INSERT INTO SurveyResultsExported(userid,"
Dim strNames,strValues2
tempArr =拆分(sArray,,)
for i = 0 to(UBound(tempArr)-1)
值=拆分(tempArr(i)," =")
''创建字段名称列表
strNames = strNames& Values(0)&" ;,
''创建值列表
strValues2 = strValues2&"''"& Values(1)&" '',"
next
''构建SQL STRING然后去吧
str_sql2 = str_sql2& left(strNames,(Len(strNames)-1))&")
VALUES(&&&pactid&","& left(strValues2) ,(Len(strValues2)-1))&")"
''cn80.execute(str _sql2)
response.write(str_sql2)
response.end
cn80.Close
设置cn80 =没什么
%>
谢谢你的帮助。
webb
I have a table with a huge amount of data.
At present my data is like so.
userid:1588 | 1 | CR1
userid:1588 | 2 | CR2
userid:1588 | 1 | CR3
userid:1588 | 1 | CR4
userid:1588 | 1 | CR5
userid:1588 | 2 | CR6
Intened format below:
userid | CR1| CR2| CR3| CR4| CR5| CR6 "Columns"
1588| 1| 2| 1| 1| 1| 2 "Data"
I already figured out how to get the data out with some great help.
But it works for one record.
I have 4342 records how can i loop the routine below to get all id''s fro me.
I tried the following but i''m missing something.
dim ID, fArray
str ="SELECT userid FROM RESULTED GROUP BY userid"
Set rsx = cn80.Execute(str)
Do while not rsx.EOF
ID = rsx("userid")
fArray = fArray & ID &","
rsx.movenext
Loop
members = fArray
selections = Split(members, ",")
for j = 0 To UBound(selections)
''run the normail routine here which is below
next
<%
dim userid, numbers, cid, sArray
str="SELECT userid, critic_result, criticId from RESULTED WHERE userid=''" &
selections(j)& "''"
Set rs = cn80.Execute(str)
Do while not rs.EOF
numbers = rs("critic_result")
cid = rs("criticId")
userid = rs("userid")
sArray = sArray & "cr"&cid &"="& numbers &","
rs.movenext
Loop
''Response.write sArray
'' open recordset
str_sql2 = "INSERT INTO SurveyResultsExported (userid, "
Dim strNames,strValues2
tempArr = Split(sArray,",")
for i = 0 to (UBound(tempArr)-1)
Values = split(tempArr(i),"=")
''CREATE FIELD NAME LIST
strNames = strNames & Values(0) & ","
''CREATE VALUE LIST
strValues2 = strValues2 & "''" & Values(1) & "'', "
next
''BUILD SQL STRING then go for it
str_sql2 = str_sql2 & left(strNames, (Len(strNames)-1)) & ")
VALUES ("&pracid&", " & left(strValues2, (Len(strValues2)-1)) & ")"
''cn80.execute(str_sql2)
response.write(str_sql2)
response.end
cn80.Close
Set cn80 = Nothing
%>
Thank you for you help.
webb
推荐答案
webb写道:
我有一张包含大量数据的表格。
目前我的数据是这样的。
userid:1588 | 1 | CR1
用户ID:1588 | 2 | CR2
用户ID:1588 | 1 | CR3
用户ID:1588 | 1 | CR4
用户ID:1588 | 1 | CR5
用户ID:1588 | 2 | CR6
下面的加密格式:
userid | CR1 | CR2 | CR3 | CR4 | CR5 | CR6专栏
1588 | 1 | 2 | 1 | 1 | 1 | 2数据
我已经想出了如何在一些很好的帮助下获取数据。
但它适用于一条记录。
我有4342记录我如何循环下面的例程以获取所有id''s
来自我。
I have a table with a huge amount of data.
At present my data is like so.
userid:1588 | 1 | CR1
userid:1588 | 2 | CR2
userid:1588 | 1 | CR3
userid:1588 | 1 | CR4
userid:1588 | 1 | CR5
userid:1588 | 2 | CR6
Intened format below:
userid | CR1| CR2| CR3| CR4| CR5| CR6 "Columns"
1588| 1| 2| 1| 1| 1| 2 "Data"
I already figured out how to get the data out with some great help.
But it works for one record.
I have 4342 records how can i loop the routine below to get all id''s
fro me.
您使用的数据库类型和版本是什么?
>
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我
不经常检查它。如果您必须离线回复,请删除
NO SPAM
What database type and version are you using?
--
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"
" webb" ; <我们***** @ theweb.com>在留言中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
"webb" <we*****@theweb.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
我有一张包含大量数据的表格。
目前我的数据是这样的。
userid:1588 | 1 | CR1
用户ID:1588 | 2 | CR2
用户ID:1588 | 1 | CR3
用户ID:1588 | 1 | CR4
用户ID:1588 | 1 | CR5
用户ID:1588 | 2 | CR6
下面的加密格式:
userid | CR1 | CR2 | CR3 | CR4 | CR5 | CR6专栏
1588 | 1 | 2 | 1 | 1 | 1 | 2数据
我已经想出了如何在一些很好的帮助下获取数据。
但它适用于一条记录。
我有4342记录我如何循环下面的例程以获取所有ID'
我。
我尝试了以下但我错过了一些>
在Recordset对象上有一个非常方便的GetSTring函数
来自MSDN的样本
这个例子演示了GetString方法。
假设你正在调试一个数据访问问题,想要一个快速,简单的方法
打印一个小的当前内容记录集。
''BeginGetStringVB
''要集成此代码
''替换数据源和初始目录值
连接字符串中的
''
Public Sub Main()
错误GoTo ErrorHandler
''连接变量
Dim Cnxn As ADODB.Connection
Dim rstAuthors As ADODB.Recordset
Dim strCnxn As String
Dim strSQLAuthors As String
Dim varOutput As Variant
''特定变量
Dim strPrompt As String
Dim strState As String
''open n连接
设置Cnxn =新ADODB.Connection
strCnxn =" Provider =''sqloledb''; Data Source =''MySqlServer'';" &安培; _
" Initial Catalog =''Pubs''; Integrated Security =''SSPI'';"
Cnxn.Open strCnxn
>
''获取用户输入
strPrompt ="输入州(CA,IN,KS,MD,MI,OR,TN,UT):
strState = Trim(InputBox(strPrompt,GetString示例))
''开放记录集
设置rstAuthors = New ADODB.Recordset
strSQLAuthors =" SELECT au_fname,au_lname,address,city FROM Authors"
& _
" WHERE state =''" &安培; strState& "''"
rstAuthors.Open strSQLAuthors,Cnxn,adOpenStatic,adLockReadOnly,
adCmdText
如果不是rstAuthors。 EOF然后
''使用所有默认值:获取所有行,TAB作为列分隔符,
''CARRIAGE RETURN作为行分隔符,EMPTY-string作为空分隔符
varOutput = rstAuthors.GetString(adClipString)
''打印输出
Debug.Print" State =''" &安培; strState& "''"
Debug.Print" Name Address City" &安培; vbCr
Debug.Print varOutput
否则
Debug.Print没有找到state ='''的行&安培; strState& "" &安培; vbCr
结束如果
''清理
rstAuthors.Close
Cnxn.Close
设置rstAuthors = Nothing
设置Cnxn = Nothing
退出Sub
ErrorHandler:
''清理
如果不是rstAuthors什么都没有那么
如果rstAuthors.State = adStateOpen那么rstAuthors.Close
结束如果
设置rstAuthors = Nothing
如果不是Cnxn则没有那么
如果Cnxn.State = adStateOpen那么Cnxn.Close
结束如果
设置Cnxn = Nothing
如果Err<> 0然后
MsgBox Err.Source& " - >" &安培; Err.Description,错误
结束如果
结束次级
''EndGetStringVB
昏暗的ID ,fArray
str =" SELECT userid FROM RESULTED GROUP BY userid"
设置rsx = cn80.Execute(str)
请不要rsx.EOF
ID = rsx(" userid")
fArray = fArray& ID&","
rsx.movenext
循环
members = fArray
selections =拆分(成员,",")
for j = 0 To UBound(选择)
''运行下面的normail例程
下一页
< ;%
昏暗的用户ID,数字,cid,sArray
str =" SELECT userid,critic_result,critId from RESULTED WHERE userid =''"
&
选择(j)& "''"
设置rs = cn80.Execute(str)
请不要rs.EOF
numbers = rs(&critic_result")
cid = rs(" criticId")
userid = rs(" userid")
sArray = sArray& cr& cid&" ="&数字&","
rs.movenext
循环
''Response.write sArray
''开放记录集
str_sql2 =" INSERT INTO SurveyResultsExported(userid,"
Dim strNames,strValues2
tempArr = Split(sArray,",")
for i = 0 to( UBound(tempArr)-1)
值= split(tempArr(i)," =")
''创建字段名称列表
strNames = strNames&值(0)&","
''创建值列表
strValues2 = strValues2&"''"& Values(1)&"'' ,
下一步
''构建SQL STRING然后去吧
str_sql2 = str_sql2& left(strNames,(Len(strNames) )-1))&")
VALUES(& pracid&","& left(strValues2,(Len(strValues2)-1))&")" br />
''cn80.execute(str_sql2)
response.write(str_sql2)
response.end
cn80。关闭
设置cn80 =没什么
%>
谢谢你的帮助。
webb
I have a table with a huge amount of data.
At present my data is like so.
userid:1588 | 1 | CR1
userid:1588 | 2 | CR2
userid:1588 | 1 | CR3
userid:1588 | 1 | CR4
userid:1588 | 1 | CR5
userid:1588 | 2 | CR6
Intened format below:
userid | CR1| CR2| CR3| CR4| CR5| CR6 "Columns"
1588| 1| 2| 1| 1| 1| 2 "Data"
I already figured out how to get the data out with some great help.
But it works for one record.
I have 4342 records how can i loop the routine below to get all id''s fro
me.
I tried the following but i''m missing something>
There is a very convenient function GetSTring on the Recordset object
Sample from MSDN
This example demonstrates the GetString method.
Assume you are debugging a data access problem and want a quick, simple way
of printing the current contents of a small Recordset.
''BeginGetStringVB
''To integrate this code
''replace the data source and initial catalog values
''in the connection string
Public Sub Main()
On Error GoTo ErrorHandler
'' connection variables
Dim Cnxn As ADODB.Connection
Dim rstAuthors As ADODB.Recordset
Dim strCnxn As String
Dim strSQLAuthors As String
Dim varOutput As Variant
'' specific variables
Dim strPrompt As String
Dim strState As String
'' open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider=''sqloledb'';Data Source=''MySqlServer'';" & _
"Initial Catalog=''Pubs'';Integrated Security=''SSPI'';"
Cnxn.Open strCnxn
'' get user input
strPrompt = "Enter a state (CA, IN, KS, MD, MI, OR, TN, UT): "
strState = Trim(InputBox(strPrompt, "GetString Example"))
'' open recordset
Set rstAuthors = New ADODB.Recordset
strSQLAuthors = "SELECT au_fname, au_lname, address, city FROM Authors "
& _
"WHERE state = ''" & strState & "''"
rstAuthors.Open strSQLAuthors, Cnxn, adOpenStatic, adLockReadOnly,
adCmdText
If Not rstAuthors.EOF Then
'' Use all defaults: get all rows, TAB as column delimiter,
'' CARRIAGE RETURN as row delimiter, EMPTY-string as null delimiter
varOutput = rstAuthors.GetString(adClipString)
'' print output
Debug.Print "State = ''" & strState & "''"
Debug.Print "Name Address City" & vbCr
Debug.Print varOutput
Else
Debug.Print "No rows found for state = ''" & strState & "''" & vbCr
End If
'' clean up
rstAuthors.Close
Cnxn.Close
Set rstAuthors = Nothing
Set Cnxn = Nothing
Exit Sub
ErrorHandler:
'' clean up
If Not rstAuthors Is Nothing Then
If rstAuthors.State = adStateOpen Then rstAuthors.Close
End If
Set rstAuthors = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
''EndGetStringVB
dim ID, fArray
str ="SELECT userid FROM RESULTED GROUP BY userid"
Set rsx = cn80.Execute(str)
Do while not rsx.EOF
ID = rsx("userid")
fArray = fArray & ID &","
rsx.movenext
Loop
members = fArray
selections = Split(members, ",")
for j = 0 To UBound(selections)
''run the normail routine here which is below
next
<%
dim userid, numbers, cid, sArray
str="SELECT userid, critic_result, criticId from RESULTED WHERE userid=''"
&
selections(j)& "''"
Set rs = cn80.Execute(str)
Do while not rs.EOF
numbers = rs("critic_result")
cid = rs("criticId")
userid = rs("userid")
sArray = sArray & "cr"&cid &"="& numbers &","
rs.movenext
Loop
''Response.write sArray
'' open recordset
str_sql2 = "INSERT INTO SurveyResultsExported (userid, "
Dim strNames,strValues2
tempArr = Split(sArray,",")
for i = 0 to (UBound(tempArr)-1)
Values = split(tempArr(i),"=")
''CREATE FIELD NAME LIST
strNames = strNames & Values(0) & ","
''CREATE VALUE LIST
strValues2 = strValues2 & "''" & Values(1) & "'', "
next
''BUILD SQL STRING then go for it
str_sql2 = str_sql2 & left(strNames, (Len(strNames)-1)) & ")
VALUES ("&pracid&", " & left(strValues2, (Len(strValues2)-1)) & ")"
''cn80.execute(str_sql2)
response.write(str_sql2)
response.end
cn80.Close
Set cn80 = Nothing
%>
Thank you for you help.
webb
我正在使用SQL Server 2000.
Webb
" Bob Barrows [MVP]" <再****** @ NOyahoo.SPAMcom>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
I''m using SQL Server 2000.
Webb
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
什么数据库您使用的是类型和版本吗?
- Microsoft MVP - ASP / ASP.NET
请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我不经常检查它。如果您必须离线回复,请删除
NO SPAM
What database type and version are you using?
--
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"
这篇关于数组到另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!