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

How to use a value from one recordset in another..?

Im doing a select that should retrieve a name from one table and display the
number of correct bets done in the betDB (using the gameDB that has info on
how a game ended)

I want the "MyVAR" value to be used in the inner select statement without
too much hassle. As you can see im trying to get the "MyVAR" to insert in
the bottom line of the code.

Whats the quick fix to this one..?

Thanks in advance :-)

---------- code begin ----------
select memberDB.memberID as MyVAR, (select count(GamesDB.GameID)
from GamesDB
inner join GameBetDB
on GameBetDB.betHome = GamesDB.homeGoal and GameBetDB.betAway =
GamesDB.awaygoal
inner join memberDB
on memberDB.memberID = GameBetDB.memberID
where GamesDB.gameID=GameBetDB.gameID
and GameBetDB.memberID= MyVAR ) as wins from memberDB
---------- code end ----------
Jul 20 '05 #1
1 1046
Bane (ba**@noname.net) writes:
Im doing a select that should retrieve a name from one table and display
the number of correct bets done in the betDB (using the gameDB that has
info on how a game ended)

I want the "MyVAR" value to be used in the inner select statement without
too much hassle. As you can see im trying to get the "MyVAR" to insert in
the bottom line of the code.

Whats the quick fix to this one..?

Thanks in advance :-)

---------- code begin ----------
select memberDB.memberID as MyVAR, (select count(GamesDB.GameID)
from GamesDB
inner join GameBetDB
on GameBetDB.betHome = GamesDB.homeGoal and GameBetDB.betAway =
GamesDB.awaygoal
inner join memberDB
on memberDB.memberID = GameBetDB.memberID
where GamesDB.gameID=GameBetDB.gameID
and GameBetDB.memberID= MyVAR ) as wins from memberDB
---------- code end ----------


Well, the answer to the question as posted is: use aliases, like this:

select m.memberID as MyVAR,
(select count(g.GameID)
from GamesDB g
join GameBetDB gb on gb.betHome = g.homeGoal
and gb.betAway = g.awaygoal
join memberDB m2 on m2.memberID = gb.memberID
where g.gameID=gb.gameID
and gb.memberID = m.memberID) as wins
from memberDB m

But that inner memberDB does not make any sense to me. I think you
are better off with:

select m.memberID as MyVAR,
(select count(g.GameID)
from GamesDB g
join GameBetDB gb on gb.betHome = g.homeGoal
and gb.betAway = g.awaygoal
where g.gameID=gb.gameID
and gb.memberID = m.memberID) as wins
from memberDB m
Then of course the join conditions between GamesDB and GameBetDB looks
funny. Surely g.gameID = gb.gameID is the join condition? The other two
looks more like filter to me. (This is a theoretical issue only, though,
and does not affect the result.)

And finally I don't see the need for the nested subquery. Maybe it is
as simple as?
select m.memberID, count(g.GameID)
from GamesDB g
join GameBetDB gb on g.gameID=gb.gameID
and gb.betHome = g.homeGoal
and gb.betAway = g.awaygoal
join memberDB m on m.memberID = gb.memberID
group by m.memberID

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p...
20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
13
by: shank | last post by:
How do you return the highest value in a recordset of maybe 100 records? Is it necessary to run 2 recordsets? I was hoping it was as simple as Max(), but no luck. thanks
4
by: dmiller23462 | last post by:
So here's my problem.....I need to set up different email distributions based on which option in the following Select form has been chosen....For instance if "Putaway" is chosen it needs to email...
2
by: Roger Withnell | last post by:
How do I find the maximum value of a recordset column? I'd rather do it this way than open a new recordset with Max(column). Thanks in anticipation. Posted Via Usenet.com Premium Usenet...
3
by: William Wisnieski | last post by:
Hello Again, I'm really stuck on this one.....so I'm going to try a different approach to this problem. I have a query by form that returns a record set in a datasheet. The user double...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
0
by: sienayr | last post by:
Greetings, I have searched hi and lo through the groups and haven't found my problem specifically. I have listed below what I have tried based on what I have found in the groups. Please let me...
5
by: bryan.com | last post by:
There must be a way. I'm making a selection from a drop-down list that had an ID number as the value and displays a text field. After submitting the data to the database I am sending an email and...
1
by: zoeb | last post by:
Currently I have a table, and would like the calculate a field in the table by referencing values from another 3 tables. i.e. tblData Index1, Index2, Index3, Value 1 2 3 2...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.