I currently have an asp.net page, that takes in the data from this view and based on the percentage it will change the text of an amount field. Meaning that if a user reaches a certain percentage they get a certain incentive amount.
However, I am currently doing this in my program however, for reporting purposes i want to be able to do this straight directly in sql, and not in my asp.net page.
what i am trying to do is almost
something like if percentage column =
65 to 70 percent then amount column =
50 if percentage column = 70 to 75
percent then amount column = 75straight in my dataview and not in my
asp.net page
If Decimal.Parse(percent.Text) >= 0.65 And percent.Text < 0.7 Then
Amount.Text = 50
ElseIf Decimal.Parse(percent.Text) >= 0.7 And percent.Text < 0.75 Then
Amount.Text = 75
ElseIf Decimal.Parse(percent.Text) >= 0.75 And percent.Text < 0.8 Then
Amount.Text = 200
ElseIf Decimal.Parse(percent.Text) >= 0.8 And percent.Text < 0.85 Then
Amount.Text = 500
ElseIf Decimal.Parse(percent.Text) >= 0.85 And percent.Text < 0.9 Then
Amount.Text = 625
ElseIf Decimal.Parse(percent.Text) >= 0.9 And percent.Text < 0.95 Then
Amount.Text = 750
ElseIf Decimal.Parse(percent.Text) >= 0.95 And percent.Text < 1.0 Then
Amount.Text = 1000
Here is my view query, i almost want to add an if statement but im not sure if it is the best way of doing this.
SELECT TOP (100) PERCENT SUM(yes) AS Countreported, SUM(no) AS Countnotreported, SUM(yes) + SUM(no) AS count, BMM, BYYYY, userid, SUM(pax)
AS party, CAST(SUM(yes) AS decimal(4, 1)) / (SUM(yes) + SUM(no)) AS percentage
FROM (SELECT SUM(CASE WHEN [insreported] IS NULL THEN 0 WHEN [insreported] = 'YES' THEN 1 ELSE 0 END) AS yes,
SUM(CASE WHEN [insreported] IS NULL THEN 1 WHEN [insreported] = 'YES' THEN 0 ELSE 1 END) AS no, CASE WHEN USERID = 'chrisn' OR
USERID = 'CHRISN' THEN 'chrism' ELSE USERID END AS userid, dbo.agent_insurance_incentive_data.BMM,
dbo.agent_insurance_incentive_data.BYYYY, SUM(dbo.agent_insurance_incentive_data.PARTY) AS pax,
dbo.incentive_agents.department
FROM dbo.agent_insurance_incentive_data LEFT OUTER JOIN
dbo.incentive_agents ON dbo.agent_insurance_incentive_data.USERID = dbo.incentive_agents.agent
WHERE (dbo.agent_insurance_incentive_data.DYYYY >= '2009') AND (dbo.agent_insurance_incentive_data.BYYYY > 2008)
GROUP BY dbo.agent_insurance_incentive_data.USERID, dbo.agent_insurance_incentive_data.BMM, dbo.agent_insurance_incentive_data.BYYYY,
dbo.agent_insurance_incentive_data.DMM, dbo.agent_insurance_incentive_data.DYYYY, dbo.incentive_agents.department)
AS derived
WHERE (userid IN
(SELECT agent
FROM dbo.incentive_agents AS incentive_agents_1)) OR
(userid = 'chrisn')
GROUP BY BMM, BYYYY, userid
ORDER BY userid, BYYYY, BMM
Conceptually this should be fairly simple. Just adopt the following formula to your query.
EDIT:
Since I can’t (don’t have the time) to re-create your tables & data.
Shouldn’t you be able to do something like: