Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:42:40+00:00 2026-06-03T05:42:40+00:00

I am using VS 2008 (asp.net with c#) and SQL Server 2005 …. Subject

  • 0

I am using VS 2008 (asp.net with c#) and SQL Server 2005….

Subject table:

create table subject
(subid varchar(10),
subname varchar(20))

sample data:

subid           subname

1               subject1
2               subject2
3               subject3

=> it includes all the subjects’ details in each row, for example:

Result table: Sampledata

studentid     subid        subname             marks

1             1            subject1            12
1             2            subject2            23
1             3            subject3            22
1             4            subject4            20

I want something like this:

studentid     subject1    subject2    subject3    subject4

1             12          23          22           20

2

3

So, I want to display each subject with its marks in column wise…

If I create a static table like…

create table subject    
(subject1 varchar(20),
 subject2 varchar(20),
 subject3 varchar(20))

NOTE:
Then it’s not possible because the subjects might change per semester (in subject table). That’s why I want to create/edit/delete tables dynamically within an ASP.NET web form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:42:41+00:00Added an answer on June 3, 2026 at 5:42 am

    A couple of things. First, in the results table, the subject name is not necessary, and actually de-normalizes the database. Should be like this:

    studentid     subid        marks
    
    1             1            12
    1             2            23
    1             3            22
    1             4            20
    

    Now, to query:

    SELECT s.subjname, r.studentid, r.marks
    FROM subject s
        INNER JOIN result r on s.subid = r.subid
    

    To get the table you want, listing out each student’s marks, use a pivot query like this:

    SELECT studentid, 
    [Subject1], [Subject2], [Subject3], [Subject4]
    FROM
    (SELECT s.subjname, r.studentid, r.marks
        FROM subject s
            INNER JOIN result r on s.subid = r.subid
    ) AS SourceTable
    PIVOT
    (
    AVG(marks)
    FOR subjname IN ([Subject1], [Subject2], [Subject3], [Subject4])
    ) AS PivotTable;
    

    You can make the pivot query dynamic as needed. Not necessary to construct dynamic tables on the fly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Visual Studio 2008 (Asp.net (c#)) and SQl Server 2005 I have a
I'm using SQL Server 2005 and asp.net 2008 with c#...I have 2 tables Result
I'm developing an ASP.NET app (C#) that connect to SQL Server 2008 using ADO.NET
I have an asp.net web application written in C# using a SQL Server 2008
I am using ASP.NET with SQL Server 2005. My date get saved in the
I am using SQL Server 2008 in a asp.net/c# program. I am trying to
I am developing an asp.net application ,, currently i'm using Sql Server 2008 as
I am using ASP.NET MVC2 in Visual Studio 2008. I believe the SQL Server
I am using ASP.NET MVC2 in Visual Studio 2008. I believe the SQL Server
I am using ADO.Net + C# + VSTS 2008 + SQL Server 2005 .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.