473,378 Members | 1,422 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,378 software developers and data experts.

cursors with where clause

6
I am trying to loop thru a cursor with 100 rows in it and get one record from a 2nd table that matches on a field called "Name". they are unique names in the 100 row cursor.

I want the record from the 2nd table to be based on 3 fields' order:

name costa costb costc
Apple 999 999 3.00
Apple 1.01 1.33 1.50
Apple 0.78 0.77 1.60
Apple 2.50 999 1.50

in this case I would want the 3rd one -- the sort order being costa, costb, costc desc.

how can I do this in one select statement instead of using a cursor? I am using sql 2000.

thanks.
Apr 5 '07 #1
3 2177
iburyak
1,017 Expert 512MB
Did you see this solution?
http://www.thescripts.com/forum/thread627490.html

Did you try it?
Apr 6 '07 #2
sbcaco
6
sorry, I didn't see your answer before I posted this question.

I tried it last night and it didn't work. here is an example of what I tried:

SELECT a.productname, b.type, b.id,
b.description, b.costa, b.costb, b.costc
from [table a] as [a]
JOIn [table b] as [b]
on a.productname = b.productname
WHERE b.costa = (SELECT top 1 costa
FROM [table b]
WHERE productname = a.productname ORDER BY costa, costb, costc desc )
and b.costb = (SELECT top 1 costb
FROM [table b]
WHERE productname = a.productname ORDER BY costa, costb, costc desc )
and b.costc = (SELECT top 1 costc
FROM [table b]
WHERE productname = a.productname ORDER BY costa, costb, costc desc )

-------------------------
I got this error message:
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'b.type'.

thanks!


Did you see this solution?
http://www.thescripts.com/forum/thread627490.html

Did you try it?
Apr 6 '07 #3
iburyak
1,017 Expert 512MB
In my original query I don't have following columns that were added by you .
Make sure that all columns you add exist in your tables.


[PHP]
b.type, b.id, b.description, [/PHP]



Good Luck.
Apr 6 '07 #4

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

Similar topics

3
by: John Doe | last post by:
et al, I've tried to find out on the 'net how to do this but can't seem to find it anywhere. How can I changed the cursors that show up in a windows application to be specific cursors that I...
11
by: Alban Hertroys | last post by:
Oh no! It's me and transactions again :) I'm not really sure whether this is a limitation of psycopg or postgresql. When I use multiple cursors in a transaction, the records inserted at the...
2
by: Rajah Venkata Krishnan | last post by:
I am trying to write updatable cursors in a stored procedure? Can I get any help to write updatable cursors? Any help would be appreciated very much. Thanks for your help in advance. Rajah...
4
by: bourgon | last post by:
Working on some new code, I'm coming across WHILE loops used instead of cursors. I was curious if anyone had any stats on how the speed of doing this compares to the speed of a cursor. I...
22
by: T.S.Negi | last post by:
Hi All, I want to avoid using cursors and loops in stored procedures. Please suggest alternate solutions with example (if possible). Any suggestion in these regards will be appreciated. ...
18
by: rcamarda | last post by:
I think cursors might help me, but I'm not sure. I'm looking for ideas on how to solve a problem I have. Consider two tables, one table contains student information (very wide 100 fields) , the...
5
by: Todd Huish | last post by:
I have noticed something disturbing when retrieving datasets over a relatively slow line (multiple T1). I am looking at about 25 seconds to retrieve 500 rows via a php-odbc link. This same select...
10
by: Just Me | last post by:
Does Me.Cursor.Current=Cursors.WaitCursor set the current property of Me.Cursor to Cursors.WaitCursor And Me.Cursor.Current=Cursors.Default set the Me.Current property to something (default)...
3
by: schwartzenberg | last post by:
Dear friends, I have just run into a strange DB2 problem. Something i'd some of you would answer, if only shortly. My basic question is: How do i ensure 'insensitive' (ie static) cursors...
1
by: Dima Kuchin | last post by:
Hello, I was trying to find the information about when and where should I use cursors in DB2, no luck. Maybe you can point me to some article that describes just that (or tell me which page is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.