473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Looping through recordset creating calculated Rank Column

1
Ok, I am racking my head over how to efficently do this in Sql Server 2000. This code is going slow.......very slow.......and direction would be appreciated.



dim rs1
dim rs2
dim cn
dim sSql
dim cmd

' instantiate the ADO objects
set cn = CreateObject("ADODB.Connection")

cn.Open = "Provider=SQLOLEDB;Data Source=(Local);Initial Catalog=Ave;User ID=sa;Password=bigmak10"

'Find distinct express numbers in sales table
sSql = "SELECT DISTINCT EXPRESS FROM SMART_SALES ; "

set rs1 = CreateObject("ADODB.Recordset")
rs1.open sSql , cn
do until rs1.eof
sSql = "SELECT SMART_SALES.EXPRESS, SMART_FUND_LIST.[Fund Long Name], SUM(SMART_SALES.FY_SALES) AS GROSS_SALES "& _
"FROM SMART_SALES INNER JOIN "& _
"SMART_FUND_LIST ON SMART_SALES.FUND_NUM = SMART_FUND_LIST.[Fund TA Fund Num] "& _
"GROUP BY SMART_SALES.EXPRESS, SMART_FUND_LIST.[Fund Long Name] "& _
"HAVING (SUM(SMART_SALES.FY_SALES) > 5000) AND (SMART_SALES.EXPRESS = '" & rs1("express").value & "') "& _
"ORDER BY SUM(SMART_SALES.FY_SALES) DESC "
set rs2 = CreateObject("ADODB.Recordset")
rs2.Open sSql, cn
i = 0
Do Until rs2.EOF
i = i + 1
set cmd = createobject("ADODB.COMMAND")
cmd.activeconnection = cn
cmd.commandtype = adCmdText
cmd.commandtext = "insert into SMART_SALES_EXPRESS_FUND ( express, [Fund Long Name], Gross_sales, rank ) "& _
"values ('" & rs1("express").value & "', '" & rs2("Fund Long Name").value & "', " & rs2("Gross_sales").value & ", " & i & " ) "
cmd.execute, adAsyncExecute
set cmd = nothing
rs2.movenext
Loop
rs2.Close
Set rs2 = Nothing

rs1.movenext
loop

rs1.close
set rs1 = nothing

cn.close
set cn = nothing

Main = DTSTaskExecResult_Success
End Function
Aug 1 '08 #1
2 2127
Stang02GT
1,208 Expert 1GB
This is not the correct forum for technical questions. And please use [code] tags when posting code!


Thank you
Aug 2 '08 #2
ck9663
2,878 Expert 2GB
Can't read it well.

Could you post some sample data and the result you're trying to achieve?

-- CK
Aug 5 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Rob Meade | last post by:
Lo all, Ok - this is what I was aiming to do, and then I thought - naahhh, that cant be right! query database results to recordset results to array using GetRows update values in one column...
4
by: Ola Tuvesson | last post by:
I'm having a really weird problem. When running the SP below in query analyzer the calculated column "Subscribed" is returned as expected: ------------- CREATE PROCEDURE get_mailinglists( ...
3
by: Indraneel Sheorey | last post by:
Hello, I want to set up a query in SQL Server that is "grouped by" a variable PRICE. Since PRICE takes on continuous decimal values, I want to create deciles based on this variable and then...
2
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, whose Default View is set to Continuos Forms. The following is the coding that I inserted in frmHistory's On Open event; it is intended to calculate the...
11
by: Dacuna | last post by:
Is it possible to use a recursive function to loop through a recordset faster? I have a table that I need to edit its contents after doing some calculation. The table has one field has an RawData...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
17
by: radio1 | last post by:
Configuration: Access 2002 and SQL Server 2000 using a .ADP Project. I would VERY MUCH appreciate anyone's input into this problem I'm having. I have a form in Access that does not permit...
7
by: tdr | last post by:
I need to compare table 1 to table 2 and if the row/recordset in table 1 is different from table 2, write the entire row/recordset from table 1 to table 3. I can read an entire row/recordset ...
3
by: Gord | last post by:
Me again, I'm new to Access and am self teaching from a couple of books, so bear with me. (I've got a little experience with Visual Basic) As I understand so far, if I want to perform a bunch...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.