I have on table Student
StudentName Subjects Marks
Ram Phys 80
Ram Chem 70
Ram Maths 50
Ramesh Phys 60
Ramesh Chem 78
Ramesh Maths 75
i want to disply result like this:
StudentName Physics Chemistry Maths
Ram 80 70 50
Ramesh 60 78 75
any help ........pls urgent
4 1219 azimmer 200
Recognized Expert New Member
I have on table Student
StudentName Subjects Marks
Ram Phys 80
Ram Chem 70
Ram Maths 50
Ramesh Phys 60
Ramesh Chem 78
Ramesh Maths 75
i want to disply result like this:
StudentName Physics Chemistry Maths
Ram 80 70 50
Ramesh 60 78 75
any help ........pls urgent
If you use SQL Server 2000, read this: http://www.mssqltips.com/tip.asp?tip=937
If you're luck enough to use 2005 there is a much simpler way: http://www.mssqltips.com/tip.asp?tip=1019
-------------------------------------**************----------------------------
USE MASTER;
GO
CREATE DATABASE STUDENTSUBMARKS;
GO
USE STUDENTSUBMARKS;
CREATE TABLE STUDENT
(
SLNO INT NOT NULL,
STUDENTNAME VARCHAR(50) NULL,
SUBJECTS VARCHAR(25) NULL,
SUBJECTMARKS BIGINT
);
GO
INSERT INTO STUDENT VALUES(1, 'RAM', 'PHYSICS', 80);
INSERT INTO STUDENT VALUES(1, 'RAM', 'CHEMISTRY', 70);
INSERT INTO STUDENT VALUES(1, 'RAM', 'MATHS', 50);
INSERT INTO STUDENT VALUES(2, 'RAMESH', 'PHYSICS', 60);
INSERT INTO STUDENT VALUES(2, 'RAMESH', 'CHEMISTRY', 78);
INSERT INTO STUDENT VALUES(2, 'RAMESH', 'MATHS', 75);
SELECT * FROM STUDENT
-------------------------------------**************----------------------------
1 RAM PHYSICS 80
1 RAM CHEMISTRY 70
1 RAM MATHS 50
2 RAMESH PHYSICS 60
2 RAMESH CHEMISTRY 78
2 RAMESH MATHS 75
------------------------------------**************----------------------------------
Hope this is useful to you and it will work.....
Happy Coding...
Regards,
Laksh
i dont want to insert i want to get that in select query result
-------------------------------------**************----------------------------
USE MASTER;
GO
CREATE DATABASE STUDENTSUBMARKS;
GO
USE STUDENTSUBMARKS;
CREATE TABLE STUDENT
(
SLNO INT NOT NULL,
STUDENTNAME VARCHAR(50) NULL,
SUBJECTS VARCHAR(25) NULL,
SUBJECTMARKS BIGINT
);
GO
INSERT INTO STUDENT VALUES(1, 'RAM', 'PHYSICS', 80);
INSERT INTO STUDENT VALUES(1, 'RAM', 'CHEMISTRY', 70);
INSERT INTO STUDENT VALUES(1, 'RAM', 'MATHS', 50);
INSERT INTO STUDENT VALUES(2, 'RAMESH', 'PHYSICS', 60);
INSERT INTO STUDENT VALUES(2, 'RAMESH', 'CHEMISTRY', 78);
INSERT INTO STUDENT VALUES(2, 'RAMESH', 'MATHS', 75);
SELECT * FROM STUDENT
-------------------------------------**************----------------------------
1 RAM PHYSICS 80
1 RAM CHEMISTRY 70
1 RAM MATHS 50
2 RAMESH PHYSICS 60
2 RAMESH CHEMISTRY 78
2 RAMESH MATHS 75
------------------------------------**************----------------------------------
Hope this is useful to you and it will work.....
Happy Coding...
Regards,
Laksh
SELECT * FROM student
--SELECT count(Studentname),studentname,
--subjects FROM Student GROUP BY Subjects,studentname
SELECT studentname,
CASE WHEN subjects='Phy' THEN marks END AS Physics,
CASE WHEN subjects='Chem' THEN marks END AS Chemistry,
CASE WHEN subjects='Maths' THEN marks END AS Maths
FROM Student
SELECT DISTINCT studentname from
(SELECT studentname,
CASE WHEN subjects='Phy' THEN marks END AS Physics,
CASE WHEN subjects='Chem' THEN marks END AS Chemistry,
CASE WHEN subjects='Maths' THEN marks END AS Maths
FROM Student)A
GROUP BY StudentName
SELECT DISTINCT studentname,sum(physics) AS Physics,sum(chemistry) AS Chemistry,sum(maths) AS Maths from
(SELECT studentname,
CASE WHEN subjects='Phy' THEN marks END AS Physics,
CASE WHEN subjects='Chem' THEN marks END AS Chemistry,
CASE WHEN subjects='Maths' THEN marks END AS Maths
FROM Student)A
GROUP BY StudentName
--,physics,chemistry,maths
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Edwinah63 |
last post by:
Hi Everyone,
All the very best for 2004!!
i need urgent help with this problem, the users are about to skin me
alive!!
we have an access front end with linked to sql server 2k tables.
...
|
by: Mike |
last post by:
Hello,
I have a few rather urgent questions that I hope someone can help with (I
need to figure this out prior to a meeting tomorrow.) First, a bit of
background: The company I work for is...
|
by: Dimitri |
last post by:
PLEASE HELP,I HAVE A DATABSE WITH MULTIPLE RECORDS AS OUTLINED BELOW
EMP NO LEVEL NEXTINCREASE WAGETYPE UNIT
1000 1 0 1000
1000 1 0 1002 ...
|
by: varkey.mathew |
last post by:
Dear all,
Bear with me, a poor newbie(atleast in AD)..
I have to authenticate a user ID and password for a user as a valid
Active Directory user or not. I have created the IsAuthenticated...
|
by: AVL |
last post by:
Hi
I'm working on indexing a website. I want to restict the search to only few
file types like .doc,.txt and.ppt
How to specify the file types in the 'ixsso.Query' object
Presently i'n using...
| |
by: sangram_149 |
last post by:
hi,
i have a query which fetches the sum of amounts from a table .the
column is 19 bytes
but the query returns only the actual amount..for example ..it returns
...
-1245.00
but i want it to...
|
by: Liam.M |
last post by:
HEY GUYS,
need some urgent help here....I am querying my database based on a
DueDate field...and want to send an automated email to anyone that
falls within two months PRIOR to this "DueDate",...
|
by: JHNielson |
last post by:
I Know I've posted an Urgent message before. But I'm in the middle of system testing, and these little stupid bugs are killing me......
I have a query that checks that a set of values (the...
|
by: gopim |
last post by:
strSql = "SELECT ISNULL(max(substring(User_ID,2,len(User_ID))) + 1,'100') FROM Users";
sqlCmd.CommandText = strSql;
sqlDr = sqlCmd.ExecuteReader();
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |