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

Posted on 2014-10-27
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
Question by:powerztom
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 200 total points
ID: 40406534
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
(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.
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 40406537
Punctuations will help us first, so we can help you after.

Author Comment

ID: 40406604
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.

next round

2nd round
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

LVL 24

Expert Comment

by:Phillip Burton
ID: 40406616
Still not clear what you want.

If you want OverAllPos to be from 1-32, then use ROW_NUMBER().

Author Comment

ID: 40406638
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.
LVL 24

Assisted Solution

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

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

Accepted Solution

Vitor Montalvão earned 300 total points
ID: 40406658
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


Author Closing Comment

ID: 40406937
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. any questions hit me back.Thanks again

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql query 5 44 background worker crossthread 11 30
Regarding Disk IO 3 46
PowerShell:  Use of subproperties in a Select statement 7 25
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

749 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