Solved

If then else statement

Posted on 2008-06-17
12
260 Views
Last Modified: 2008-06-24
What I am trying to accomplish is to have a SQL select statement look in a tbl and pull out pay information for an individual.  But my problem lies in this the pay tables only go to certian yrs so that an E4-6 makes no more than an E4-8.  So the cut of would be an person with rank E-4 and over 6 years makes this scale.  so on for rest of the pay scale as well.  Here is my code so far.

I select the GRYRs from an existing label that is populated with a persons info.  I then do an sql statemnt to look up the scale such as E5-6, E4-6 so on.  Then depending on what comes back it does the calcs.  But my problem is above it returns nothing if there is an E4-8 because on the pay scale it does not exist for anything over adn E4-6 because they max out at 6 years.

 Private Sub Calc()
        Dim GrYrs As String = lblPayGrYrs.Text

        sql = "select strBase, strQtrs, strRats, strMisc, strFDWH from MNSadPaytables.dbo.tblMnSadDutyPay Where strGrdYrs = '" & GrYrs & "'"

        myDataTable = New DataTable
        myDataTable = getData(sql)

        lblstrbase.Text = myDataTable.Rows(0)(0)
        lblstrqtrs.Text = myDataTable.Rows(0)(1)
        lblstrRats.Text = myDataTable.Rows(0)(2)
        lblstrmisc.Text = myDataTable.Rows(0)(3)
        lblstrFWTH.Text = myDataTable.Rows(0)(4)

        Dim Days As String = lblDutyDays.Text
        Dim base As Decimal = lblstrbase.Text
        Dim Diff As Decimal = lblstrmisc.Text
        Dim Qtrs As Decimal = lblstrqtrs.Text
        Dim Rats As Decimal = lblstrRats.Text
        Dim FedT As Decimal = lblstrFWTH.Text
        Dim total As Decimal
        Dim Grand As Decimal
        Dim TaxTotal As Decimal
        Dim TotalCheck As Decimal

        total = base + Qtrs + Rats
        TaxTotal = FedT * Days

        If total < 130.0 Then
            Grand = (total + Diff) * Days
        Else
            Grand = total * Days
        End If

        TotalCheck = Grand - TaxTotal

        lblTotalEntitlement.Text = Grand.ToString("c")
        lblBasePay.Text = base.ToString("c")
        lblDiffPay.Text = Diff.ToString("c")
        lblHouseAllow.Text = Qtrs.ToString("c")
        lblRations.Text = Rats.ToString("c")
        lblFTWH.Text = FedT.ToString("c")
        lblTotalWH.Text = TaxTotal.ToString("c")
        lblTotalCheck.Text = TotalCheck.ToString("c")
    End Sub

End Class
0
Comment
Question by:kdeutsch
  • 6
  • 5
12 Comments
 
LVL 11

Expert Comment

by:William
ID: 21804013
Would it be simple to do the if in your code versus the sql?

if GrYrs = something
sql = "select strBase, strQtrs, strRats, strMisc, strFDWH from MNSadPaytables.dbo.tblMnSadDutyPay Where strGrdYrs = '" & GrYrs & "'"
else if GrYrs = somethingelse
sql = "select strBase, strQtrs, strRats, strMisc, strFDWH from MNSadPaytables.dbo.tblMnSadDutyPay Where strGrdYrs = '" & GrYrs & "'"
else if GrYrs = another ..........

or a switch/case statment for the different variations of GrYrs posibly
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21804411
I might recommend a change to your datatables, to keep grade and seniority separate. Then we could get the max seniority for each grade and use it instead of the submitted value.

Also, piece of cake to add more complex logic if you're using SQL Server, but tougher with Access. Slightly different syntax, so if you could let me know which you're using, I can help better.
0
 

Author Comment

by:kdeutsch
ID: 21804979
All,
Currently we import all information into SQL 200 databases with wich the paygrade and yrs are combined as such E4-6.  They won't change how they do theri spreadsheet and I don't know how to write import stored procedures.  SO i am stuck with just tyring to match what they have.  Unless there is an easier way.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21805177
Okay.... so we might have to work around this a bit.

Is the format always "grade-seniority"?
0
 

Author Comment

by:kdeutsch
ID: 21805279
Correct
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
ID: 21805459
Something like the following (might need a bit of tweaking...) should work. Essentially, we're checking for a match, and if it exists, using that value, otherwise getting the highest value for that rank.

There may be issues if 10+ years in grade is permitted.
		Dim grade As String = GrYrs.Split("-"c)(0)
 
		Dim sb As New System.Text.StringBuilder(512)
		With sb
			.Append("SELECT strBase, strQtrs, strRats, strMisc, strFDWH FROM ")
			.Append("MNSadPaytables.dbo.tblMnSadDutyPay ")
			.Append("WHERE strGrdYrs = ")
			.Append("CASE WHEN EXISTS(SELECT strGrdYrs FROM MNSadPaytables.dbo.tblMnSadDutyPay ")
			.AppendFormat("WHERE strGrdYrs = '{0}')", GrYrs)
			.AppendFormat("THEN '{0}' ", GrYrs)
			.Append("ELSE SELECT MAX(strGrdYrs) FROM MNSadPaytables.dbo.tblMnSadDutyPay ")
			.AppendFormat("WHERE strGrdYrs LIKE '{0}%' END", grade)
		End With
		Dim sql As String = sb.ToString

Open in new window

0
 

Author Comment

by:kdeutsch
ID: 21806052
Well, that would be the problem then, because this is for every rank.  I think at theis point I am going to have them list in the excel spreadsheet every rank and year, this way it makes my job easier.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21806124
well... the code above will work... unless you allow more than 10 years at a given rank...

The "tweaking" would only be because I didn't spin up a dummy database to test the syntax against... but it should be right
0
 

Author Comment

by:kdeutsch
ID: 21806291
OK, i will give it a try, would I have to make one of these for every rank.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21806628
doesn't strGrdYrs contain the rank as part of it?
0
 

Author Comment

by:kdeutsch
ID: 21806802
Yes it does, ok, I see
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21806856
yeah... a little devious is stripping out the rank there and using it as the filter for the MAX subquery :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC 2 31
localhost: This site can’t be reached  localhost refused to connect. 2 45
vb.net and creating a class 5 14
Linq asp.net mvc 13 6
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

12 Experts available now in Live!

Get 1:1 Help Now