•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 423,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,783 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 645 | Replies: 0
![]() |
•
•
Join Date: Feb 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hi there,
I am a new member of this site and I am not very much aware of T-sql's working.
My question is what if I need to get one column's data to be the heading of another column.
To be very exact I have a school's database. The table I am talking about is of the results of students. The table contains Student ID, Subject ID, Total marks of the subject, Marks obtained in the subject. Now I want to print a report by generating data from this table. Right now the data is something like this
StuID - - - -SubID - - - -Tot - - -Obt
1 - - - - - - -1 - - - - - - -50 - - - 38
1 - - - - - - -2 - - - - - - -50 - - - 41
1 - - - - - - -3 - - - - - - -50 - - - 42
1 - - - - - - -4 - - - - - - -50 - - - 40
2 - - - - - - -1 - - - - - - -50 - - - 35
2 - - - - - - -2 - - - - - - -50 - - - 40
2 - - - - - - -3 - - - - - - -50 - - - 42
2 - - - - - - -4 - - - - - - -50 - - - 41
StudentID and SubjectID fields are related to other tables so I can get the names from there but when I need the report I need the data in the form of
StuID - Sub 1 - - - Sub 2 - - - Sub 3 - - - -Sub4
1 - - - - 38 - - - - - 41 - - - - - 42 - - - - - - 40
2 - - - - 35 - - - - - 40 - - - - - 42 - - - - - - 41
I hope I am clear with my question. The subjectIDs or their names will become the headings and they will contain the obtained marks for that subjects in their columns just for the reports. I have also checked the PIVOT function but was not able to do what I wanted.
Sunny
I am a new member of this site and I am not very much aware of T-sql's working.
My question is what if I need to get one column's data to be the heading of another column.
To be very exact I have a school's database. The table I am talking about is of the results of students. The table contains Student ID, Subject ID, Total marks of the subject, Marks obtained in the subject. Now I want to print a report by generating data from this table. Right now the data is something like this
StuID - - - -SubID - - - -Tot - - -Obt
1 - - - - - - -1 - - - - - - -50 - - - 38
1 - - - - - - -2 - - - - - - -50 - - - 41
1 - - - - - - -3 - - - - - - -50 - - - 42
1 - - - - - - -4 - - - - - - -50 - - - 40
2 - - - - - - -1 - - - - - - -50 - - - 35
2 - - - - - - -2 - - - - - - -50 - - - 40
2 - - - - - - -3 - - - - - - -50 - - - 42
2 - - - - - - -4 - - - - - - -50 - - - 41
StudentID and SubjectID fields are related to other tables so I can get the names from there but when I need the report I need the data in the form of
StuID - Sub 1 - - - Sub 2 - - - Sub 3 - - - -Sub4
1 - - - - 38 - - - - - 41 - - - - - 42 - - - - - - 40
2 - - - - 35 - - - - - 40 - - - - - 42 - - - - - - 41
I hope I am clear with my question. The subjectIDs or their names will become the headings and they will contain the obtained marks for that subjects in their columns just for the reports. I have also checked the PIVOT function but was not able to do what I wanted.
Sunny
Last edited by luciano_sunny : Feb 25th, 2008 at 2:30 pm. Reason: The look of the table missed the white spaces i provided and i missed to mention one thing
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access advice breach broadband business classification code combo crime daniweb data data protection data transfer database drive dropdownlist encryption europe forensic forensics fun government hard hardware help hitachi hp industrial espionage information internet it linux module net news payment services privacy protection reuse security storage terabyte tutorials and more web wikipedia you tried to assign the null value to a variable that is not a variant data type
- Pivot table in DataGrid (VB.NET)
- Open In New Window Php (PHP)
- Hesitation Part Deux (Viruses, Spyware and other Nasties)
- Confused & frustrated (Web Developers' Lounge)
- format specifiers (Java)
- Importing csv file to SQL Server Using VB.Net (VB.NET)
- help in c++ program (C++)
- another one...selecing rows in datagrid and sorting with column headers (VB.NET)
- The Calculator (C++)
Other Threads in the MS SQL Forum
- Previous Thread: Problem in finding birthday from date of birth in SQL Server
- Next Thread: Problem with NULL in SQL 2000


Linear Mode