|
i have a table with students marks records which contains the data as follows:
admno subjectGroup Exam subject marks
4719 GROUP I CAT-01 ENGLISH 45
4719 GROUP I CAT-01 KISWAHILI 78
4719 GROUP II CAT-01 CHEMISTRY 67
4719 GROUP II CAT-01 BIOLOGY 45
4719 GROUP II CAT-01 PHYSICS 45
4719 GROUP I CAT-01 MATHEMATICS 90
4720 GROUP I CAT-01 ENGLISH 67
4720 GROUP I CAT-01 KISWAHILI 61
4720 GROUP I CAT-01 MATHEMATICS 77
4721 GROUP I CAT-01 ENGLISH 81
4722 GROUP I CAT-01 KISWAHILI 62
4723 GROUP I CAT-01 ENGLISH 89
4724 GROUP I CAT-01 KISWAHILI 63
4726 GROUP I CAT-01 ENGLISH 78
4728 GROUP I CAT-01 ENGLISH 67
4730 GROUP I CAT-01 KISWAHILI 81
4734 GROUP I CAT-01 MATHEMATICS 56
i need to add marks belonging to a particular student(admno) based on the following criteria:
for each student;
1. select 3 group I subjects
2. select the best 2 group II subjects
...kindly assist
modified 13-Apr-15 16:50pm.
|
|
|
|
|
What is your question?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
summing up marks per student(admno) based on the conditions given
|
|
|
|
|
Use a select query with a where clause on the subject group to get the group 1 students limit the output to 3 records (TSQL has a TOP function, not sure about MySQL)
For the second use the same query and change the where clause and the record limit. Add an order by on Marks to get the 2 records you need.
This is a microsoft answer, technically correct but does not meet you requirements which I suspect should have included - give me the codz!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thanks for the answer....but that works well for a single student but for many students it add all marks of all students
|
|
|
|
|
Ah my bad, I missed the add. You may need a nested select. First build your query to get the records you need and then wrap that in an aggregate query
select GroupID, sum(marks)
from(select GroupID, marks
From Table
Where Group = 'some code') X
group by GroupID
The query X gets the records you need and the outer query aggregates those records.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for the quick reply ...i have tried but could not really succeed. i managed the following
SELECT sAdmNo ,SBGROUP ,SUM(AVG) FROM (select sAdmNo,SBGroup, AVG
From (select sAdmNo,SBGroup, AVG FROM marks Where SBGroup = 'GROUP I' LIMIT 3)AS T
Where SBGroup = 'GROUP II' LIMIT 2)AS TT GROUP BY sAdmNo
...kindly elaborate on how i can add from both groups
|
|
|
|
|
i have a picturebox with a default image and want to save image to database when it contains another image apart from the default. and if the picturebox has the default image then set in the db to null.
any suggestion on how i can check that before updating the database...
i tried using this but it doesnt check:
If Me.PictureBox1.Image Is System.Drawing.Image.FromFile(My.Application.Info.DirectoryPath & "\ImageSyntax\NoImage.JPG") Then
'action
End If
|
|
|
|
|
You might try the .NET forum.
What about checksum?
Mongo: Mongo only pawn... in game of life.
|
|
|
|
|
Hi All,
I have a stored procedure as below and I am calling that stored procedure by using ExecuteQuery in asp.net application, I am calling passing the out parameter value but still it is throwing exception. I am not understanding where am I missing, I am debugging and searching too, still can't find any answer.
Can anybody please help me in this any suggestion link or code snippet would be helpful, thanks in advance.
Here is Stored Procedure parameter structure I avoided putting all stored procedure logic here to increase readability, but if you want I can put it here
ALTER PROCEDURE [dbo].[StaffSearch_sel]
(
@OverrideSecurity BIT = 0,
@UserId INT,
@SchoolYearId INT,
@Name VARCHAR(500) = NULL,
@ContractorId INT = NULL,
@SubcontractorId INT = NULL,
@SiteId INT = NULL,
@OrganizationRelationshipIds VARCHAR(500) = NULL,
@RoleTypeIds VARCHAR(200) = NULL,
@StaffMemberNeedsAllRoles BIT = 0,
@Page INT = 1,
@RowsPerPage INT = 20,
@TotalRows INT OUT,
@SortExpression VARCHAR(50) = 'LastName',
@SortDirection VARCHAR(15) = 'Ascending'
)
AS
BEGIN
---logic-----
END
And my C# code here
public static List<StaffMemberPOCO> Search(bool staffMemberNeedsAllRoles, bool overrideSecurity, string name, int schoolYearId, int? contractorId, int? subcontractor, int? siteId,
int[] roleTypeIds, int[] organizationRelationshipIds, int userId, int pageNumber, int rowsPerPage, out int totalRows, string sortExpression, string sortDirection)
{
using (var context = new ELMSContext())
{
var outputParm = new SqlParameter("TotalRows", SqlDbType.Int) { Direction = ParameterDirection.Output };
List<StaffMemberPOCO> pocos =
context.ExecuteStoreQuery<StaffMemberPOCO>("exec StaffSearch_sel @OverrideSecurity, @UserId, @SchoolYearId, @Name, @ContractorId, @SubcontractorId, @SiteId, @OrganizationRelationshipIds, @RoleTypeIds, @StaffMemberNeedsAllRoles",
new SqlParameter("@OverrideSecurity", overrideSecurity),
new SqlParameter("@UserId", userId),
new SqlParameter("@SchoolYearId", schoolYearId),
new SqlParameter("@Name", name ?? (object)DBNull.Value),
new SqlParameter("@ContractorId", contractorId ?? (object)DBNull.Value),
new SqlParameter("@SubcontractorId", subcontractor ?? (object)DBNull.Value),
new SqlParameter("@SiteId", siteId ?? (object)DBNull.Value),
new SqlParameter("@OrganizationRelationshipIds", organizationRelationshipIds == null || organizationRelationshipIds.Count() == 0 ? (object)DBNull.Value : string.Join(",", organizationRelationshipIds)),
new SqlParameter("@RoleTypeIds", roleTypeIds == null ? (object)DBNull.Value : string.Join(",", roleTypeIds)),
new SqlParameter("@StaffMemberNeedsAllRoles", staffMemberNeedsAllRoles),
new SqlParameter("@Page", pageNumber),
new SqlParameter("@RowsPerPage", rowsPerPage),
outputParm,
new SqlParameter("@SortExpression", sortExpression ?? (object)DBNull.Value),
new SqlParameter("@SortDirection", sortDirection ?? (object)DBNull.Value)
).ToList();
totalRows = ((outputParm != null) && !DBNull.Value.Equals(outputParm)) ? int.Parse(outputParm.Value.ToString()) : 0;
return pocos;
}
}
And executestorequery is throwing the following exception
System.Data.SqlClient.SqlException: Procedure or function 'StaffSearch_sel' expects parameter '@TotalRows', which was not supplied.
"There is enough hatred in the world, lets spread love compassion and affection."
|
|
|
|
|
Looks like you simply forgot the @
var outputParm = new SqlParameter("@TotalRows", SqlDbType.Int) { Direction = ParameterDirection.Output };
^^^
|
|
|
|
|
Even after putting @ also it was giving me error then I tried with this.
I have put it like this
List<StaffMemberPOCO> pocos =
context.ExecuteStoreQuery<StaffMemberPOCO>("exec StaffSearch_sel @OverrideSecurity, @UserId, @SchoolYearId, @Name, @ContractorId, @SubcontractorId, @SiteId, @OrganizationRelationshipIds, @RoleTypeIds, @StaffMemberNeedsAllRoles",
new SqlParameter("@OverrideSecurity", overrideSecurity),
new SqlParameter("@UserId", userId),
new SqlParameter("@SchoolYearId", schoolYearId),
new SqlParameter("@Name", name ?? (object)DBNull.Value),
new SqlParameter("@ContractorId", contractorId ?? (object)DBNull.Value),
new SqlParameter("@SubcontractorId", subcontractor ?? (object)DBNull.Value),
new SqlParameter("@SiteId", siteId ?? (object)DBNull.Value),
new SqlParameter("@OrganizationRelationshipIds", organizationRelationshipIds == null || organizationRelationshipIds.Count() == 0 ? (object)DBNull.Value : string.Join(",", organizationRelationshipIds)),
new SqlParameter("@RoleTypeIds", roleTypeIds == null ? (object)DBNull.Value : string.Join(",", roleTypeIds)),
new SqlParameter("@StaffMemberNeedsAllRoles", staffMemberNeedsAllRoles),
new SqlParameter("@Page", pageNumber),
new SqlParameter("@RowsPerPage", rowsPerPage),
new SqlParameter("@TotalRows", SqlDbType.Int) { Direction = ParameterDirection.Output },
new SqlParameter("@SortExpression", sortExpression ?? (object)DBNull.Value),
new SqlParameter("@SortDirection", sortDirection ?? (object)DBNull.Value)
).ToList();
totalRows = ((outputParm != null) && !DBNull.Value.Equals(outputParm)) ? int.Parse(outputParm.Value.ToString()) : 0;
And still giving the following error
Procedure or function 'StaffSearch_sel' expects parameter '@TotalRows', which was not supplied.
"There is enough hatred in the world, lets spread love compassion and affection."
modified 8-Apr-15 2:25am.
|
|
|
|
|
Please try it with this query-string:
"exec StaffSearch_sel @OverrideSecurity,
@UserId, @SchoolYearId, @Name, @ContractorId, @SubcontractorId,
@SiteId, @OrganizationRelationshipIds, @RoleTypeIds,
@StaffMemberNeedsAllRoles, @TotalRows out"
^^^^^^^^^^
|
|
|
|
|
Hi All,
I have an SSRS report when we export it to excel, it is exporting in 4 different tabs rather in one tab, I want it to be exported to one excel tab.
I have set the Disabled property in Page break of both the groups that exists to =IIF(Globals!RenderFormat.Name = "CSV" OR Globals!RenderFormat.Name = "EXCELOPENXML" OR Globals!RenderFormat.Name = "EXCEL", true, false), in report preview it is displaying correctly and generating the excel with only one sheet, but unfortunately when I try this in report viewer, it is displaying the following error
"A data source instance has not been supplied for the data source 'DataSet1'." Actually when I investigated it looks like it is missing the parameters, because the reports parameters are generated from the report dynamically some how they are not getting generated.
It runs perfectly in the report preview why isn't getting generated when I run from report viewer I am not understanding.
Can anybody please help me in this regard? I need some help any link, suggestion or code snippet any help would be really helpful.
Thanks in advance.
"There is enough hatred in the world, lets spread love compassion and affection."
modified 6-Apr-15 21:26pm.
|
|
|
|
|
i have two tables with same schema. i have to check table1 for any updates and insert the updates or the entire row into table2, only the most recently updated row.
so basically, table2 has the unique values from table1; for the duplicate entries in table1, there is only the most recent entry in table2.
i have tried to get the most recently updated id from table1:
SELECT distinct id
FROM table1 order by time_date desc limit 1;
now i need to use this id to get the other columns from table1 and insert the row with that id, into table2.
and i have to do this for all the entries in table1.
i have to update the row in table2 if it already exists, else insert new row. i check for recent record based on the date column, time_date.
both the tables have same schema.
any help would be great.!
thank you.
|
|
|
|
|
|
I'm in the process of gathering data for a form
I have 3 tables
1. CompletedOrders
2. BillingAddress
3, Shipping Address
So it works in SQL Manager when I model it, but not in code, asp.net
I just get nothing.
In sql manager, the sa doesn't light up pink, and shows like an error, but doesn't complain.
DECLARE @CompletedOrderID INT;
SET @CompletedOrderID = 3;
DECLARE @CA_ID INT, @BA_ID INT, @SA_ID INT, @CIP_ID INT, @CC_ID INT;
SET @CA_ID = (SELECT CA_ID FROM COMPLETEDORDERS WHERE CompletedOrderID = @CompletedOrderID);
SET @BA_ID = (SELECT BA_ID FROM COMPLETEDORDERS WHERE CompletedOrderID = @CompletedOrderID);
SET @SA_ID = (SELECT SA_ID FROM COMPLETEDORDERS WHERE CompletedOrderID = @CompletedOrderID);
SET @CIP_ID = (SELECT CIP_ID FROM COMPLETEDORDERS WHERE CompletedOrderID = @CompletedOrderID);
SET @CC_ID = (SELECT CC_ID FROM COMPLETEDORDERS WHERE CompletedOrderID = @CompletedOrderID);
SELECT
co.CompletedOrderID
, ba.Attention
, ba.CompanyName
, ba.StreetAddress1
, ba.StreetAddress2
, ba.City
, ba.StateCode
, ba.PostalCode
, ba.CountryCode
, ba.Phone
, sa.Attention
, sa.CompanyName
, sa.StreetAddress1
, sa.StreetAddress2
, sa.City
, sa.StateCode
, sa.PostalCode
, sa.CountryCode
, sa.Phone
FROM COMPLETEDORDERS co
LEFT JOIN CUSTOMER_BILLING_ADDRESS ba ON co.BA_ID = @BA_ID
LEFT JOIN CUSTOMER_SHIPPING_ADDRESS sa ON co.SA_ID = @SA_ID
WHERE co.CompletedOrderID = @CompletedOrderID
|
|
|
|
|
How dumb of me, I set the pointer to ByVal instead of ByRef, wiping out the results.
Time to go home I think
|
|
|
|
|
Those JOIN s don't look right. Try:
FROM
COMPLETEDORDERS co
LEFT JOIN CUSTOMER_BILLING_ADDRESS ba ON co.BA_ID = ba.BA_ID
LEFT JOIN CUSTOMER_SHIPPING_ADDRESS sa ON co.SA_ID = sa.SA_ID
You've also got five queries to select a single column from the same record. You could replace that with a single SELECT :
SELECT
@CA_ID = CA_ID,
@BA_ID = BA_ID,
@SA_ID = SA_ID,
@CIP_ID = CIP_ID,
@CC_ID = CC_ID
FROM
COMPLETEDORDERS
WHERE
CompletedOrderID = @CompletedOrderID
;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'll try it today or tomorrow, didn't know about the Select and set being able to condense it like that.
Thanks!
|
|
|
|
|
Friends,I am working on a project....and in that project i have to take scanned image of finger with the help of fingerprint scanner.....and this image will be used as a password to log in the site.....so plzzzz..tell me how to store images in database..and how can i check the scanned image of finger of user with other scanned images
|
|
|
|
|
To store an image you will need a parameterized query, but that won't help you with what you are trying to do.
|
|
|
|
|
its web based project....like u can say...whenever we want to login on facebook,gmail,etc.we have to type our alphanumeric password....but i want user to scan his/her fingerprint..and then the fingerprint will be matched(as a password)......so my main aim is to provide more security to users..
|
|
|
|
|
Yes, but I very much doubt that comparing images will work. You'll need to read up on fingerprint matching and such. You're probably better off buying something that will do it for you.
And besides, did your users ask you to do this? I know I wouldn't use a site that did that.
|
|
|
|
|
ook...let me tell u...am a student and its final project which i have to submit...yeah..this project is having wide applications in banking,industries,etc.......
basically i will interface fingerprint scanner with the server.....
|
|
|
|
|