I am having a sql problem and I want to see if anyone knows a solution.
I am attempting to pull data from sql, put it into a datagrid view, then print the data into an excel spread sheet.
Let me explain where i'm having trouble. The data must be pulled from sql already formatted, so that it goes into the data grid view then to excel.
I totally understand how to get the data out, put it into a datagrid view and then print to a formatted excel sheet.
Here is the problem:
I need the data grid view to look like the following:
Person name \ employee number \ Column 1 total \ column 1 total percent of highest value of column 1
There are a total 5 columns each with percentages.
Here is what i have so far, I apologize that it will run on and not be formatted to be read correctly, I will do my best.
Here is the sql statement I have and its not doing what I need it to do:
---------------------
Declare @MaxVar1 int
Declare @MaxVar2 int
Declare @MaxVar3 int
Declare @MaxVar4 int
Declare @MaxVar5 int
SELECT @MaxVar1 = Count(Column1) FROM dbo.Mytable WHERE Condition1 = 'VbCondition1' AND Condition2 = 'VbConditon2' GROUP BY EmployyeNum ORDER BY COUNT(Column1)
SELECT NAME, EmployeeNum, SUM(Column1), (Sum(Column1) *100 / @MaxVar1
From dbo.MyTable Where Condition1 = 'Vbcondtion1' AND Condition2 = 'VbCondition2'
Group By Name, EmployeeNum Order by @MaxVar1 Desc
-------------------
What i'm getting is the highest input for the column and not a computed total for the employee for a column. When I divide the Sum by the MaxVar I can not get the total for the employee and show the percent that the employee completed.
SQL is not letting me do a subquery inside of a query that gets a value.
Is there some other way to do this?
Any help or advice will be more than appreciated.