Solved

Grabbing the last row of a db table and then increment it.

Posted on 2014-10-27
9
197 Views
Last Modified: 2014-10-27
I have one Table called Draft which has several fields that user will select like PlayerID ,DraftTeam and Ncca Team then I have 4 remaining textboxes and here is where I don't know where to start I have a  sub that gets current year 2014 but when user goes to use this it will be 2015 so I made that field available for testing now I have 3 textboxes left one is round, one is Draft position and last is overall position at the round only increases in NFL after 32 draft positions have been reached 30 for NBA and 30 for nhl overall just increments until the end so after round 1 has been complete then round becomes 2 and Draft position goes back to 1 and based on sport increments to either 32 NFL 30 NBA AND 30 NHL. THE Issue is if any of these 3 sports adds a new team to their league. That will screw up flow cause if I hardcode 32,or 30. oh overall position is just a count which increments.
Any suggestions
0
Comment
Question by:powerztom
  • 3
  • 3
  • 2
9 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 200 total points
Comment Utility
I don't quite understand the question. Maybe examples might make it clearer.

Assuming that your problem is that you want the minimum number of matches than any team has played, and you have a Year field and a Team field, so you know that a particular team has played x matches in a particular year, then you could use:

Select min(Matches) as MinMatches
from 
(select [Year], Team, count(Team) as Matches
from Draft
where [Year] = (select max(Year) from Draft)
Group by [Year], Team) as t

Open in new window


However, as I said, what you are asking for is not clear. Maybe you could also post the structure of your tables.
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
Comment Utility
Punctuations will help us first, so we can help you after.
0
 

Author Comment

by:powerztom
Comment Utility
Sorry Guys that I was unclear I posting to screenshots one shows a complete round 1 Draft and the 2nd round 2 draft You can see the draft position stays 1to32 and overall just keeps incrementing. Here 2 screen shots
I thing I was thinking of using something like this
 Dim sql As String = "SELECT TOP 1 draftpos FROM draft ORDER BY overallpos DESC" this won't work but I know this will grab last row I'm just trying to think the logic not a SQL Master wish I was.

report1
next round

2nd round
0
 
LVL 24

Expert Comment

by:Phillip Burton
Comment Utility
Still not clear what you want.

If you want OverAllPos to be from 1-32, then use ROW_NUMBER().
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:powerztom
Comment Utility
if you look at both pics column Draftpos is the column 1-32 and look at overallpos it goes 1-32 but on 2nd round 33 to 64 that column keeps incrementing until the entire draft is done. next round Draftpos is 1-32 Each Nfl team gets a pick then it's 3rd round Draftpos 1-32 and then Overallpos is 65-100. I apologize if this is not clear. But that's what I am Tasked with.
0
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 200 total points
Comment Utility
Therefore, I would used ROW_NUMBER().

If you knew the number of teams, then I could use % as the modulo.
0
 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 300 total points
Comment Utility
Do you want to grab all row or just one field?
For full row use this query:
"SELECT TOP 1 * FROM draft ORDER BY overallpos DESC"

Open in new window

0
 

Author Closing Comment

by:powerztom
Comment Utility
Thanks Guys I feel you all deserve the points I want to ask one of you a favor tagging and on to a sql statement.
http://www.experts-exchange.com/Database/MS-SQL-Server/Q_28544250.html any questions hit me back.Thanks again
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now