Monday, February 27, 2012

how can i get this query

Hi can anybody give me a suggestion to get result like

Student ComputerGeographySocial

ID

Name

ID

SEM

Marks

ID

SEM

Marks

ID

SEM

Marks

1

ABC

1

1

80

1

2

35

1

3

88

2

CDE

2

1

60

3

2

65

2

3

45

3

XYZ

2

2

55

3

1

67

3

1

75

and I want OUTPUT as below

Name

Computers Total

Geography Total

Social Total

ABC

80

35

88

CDE

115

45

XYZ

67

65

75

how can i write a query to get it? Thanx in help

Thanx-Chinni

WHat about:

SELECT
SUM(c.Marks) AS [ComputerTotal],SUM(G.Marks) AS [Geography Total],Sum(So.Marks) AS [SocialTotal]
FROM Student S
LEFT JOIN Computer C
ON s.ID = C.ID
LEFT JOIN GeoGraphy G
ON S.ID = C.ID
LEFT JOIN Social So
ON S.ID = So.ID

Does that work for you ?

HTH, Jens SUessmeyer.

http://www.sqlserver2005.de

|||

Oh thanx its working now. But the problem is I executed this query in sql server management studio but how can I execute the same query using ado.net with c#.

I tried like this

SqlDataAdapter _sqlDataAdapter = new SqlDataAdapter("our query string ", myConnection);

Dataset _dataSet = new DataSet("student");

_sqlDataAdapter.Fill(_dataSet,"student");

But it shows error

Thanx-Nagu

|||

Oh sorry I did a small mistake and now its working any how thank you very much

Nagu

No comments:

Post a Comment