473,490 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Urgent Query

9 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
Aug 21 '07 #1
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
Aug 21 '07 #2
itsmatta
1 New Member
-------------------------------------**************----------------------------
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
Aug 21 '07 #3
rupalirane07
9 New Member
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
Aug 22 '07 #4
rupalirane07
9 New Member
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
Aug 22 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6355
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. ...
8
5206
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...
2
1583
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 ...
6
2446
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...
1
1440
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...
6
1345
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...
1
2336
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",...
2
1620
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...
5
1671
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(); ...
0
7112
marktang
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,...
0
7146
Oralloy
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,...
0
7183
jinu1996
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...
1
6852
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...
1
4878
isladogs
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...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
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 ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.