How do i make pivot without using pivot function. Those data is related by parameter @semester. It can be any semester.
DECLARE @Semester VARCHAR(10)
SET @Semester = '1'
CREATE TABLE #Students (
MatricNo INT PRIMARY KEY,
Name VARCHAR(100),
Final1 INT,
Grade varchar(2)
)
INSERT INTO #Students VALUES(888999, 'Hazel', 221, 'F')
CREATE TABLE #Marks(
MatricNo INT,
Semester VARCHAR(10),
Test VARCHAR(50),
Marks INT
)
INSERT INTO #Marks VALUES(888999, 1, '1', 15)
INSERT INTO #Marks VALUES(888999, 1, '2', 10)
INSERT INTO #Marks VALUES(888999, 1, '3', 10)
INSERT INTO #Marks VALUES(888999, 1, '4', 20)
INSERT INTO #Marks VALUES(888999, 2, '1', 25)
INSERT INTO #Marks VALUES(888999, 2, '2', 20)
INSERT INTO #Marks VALUES(888999, 2, '3', 30)
CREATE TABLE #Test(
TestID INT,
Test Name VARCHAR(40)
)
INSERT INTO #TestVALUES(1, 'Assignment_1')
INSERT INTO #TestVALUES(2, 'Assignment_2')
INSERT INTO #TestVALUES(3, 'Presentation')
INSERT INTO #TestVALUES(4, 'Project')
Finally, it can be either 1st look
Matric No. | Name | Assignment 1 | Assignment 2 | Presentation | Project | Final | Grade | Point
888999 | Hazel | 15 | 10 | 10 | 20 | 45 | F | 0
OR 2nd Look
Matric No. | Name | Assignment 1 | Assignment 2 | Final | Grade | Point
888999 | Hazel | 15 | 10 | 45 | F | 0
Hazel MahmudPosted Jul 16, 2024, 2:00 AM
STRING_AGG is not recognize keyword in sybase . how to change ?
Naveen KumarPosted Jul 15, 2024, 3:06 AM
Yes you can use CASE in dynamic, see the below query.
Hazel MahmudPosted Jul 15, 2024, 1:07 AM
i know how to pass the value from dropdown select but can i use CASE if the testID is dynamic?..
Naveen KumarPosted Jul 14, 2024, 11:12 AM
Create a parameterized stored procedure with input parameter as Semester and pass the value from dropdown select.
Hazel MahmudPosted Jul 14, 2024, 7:46 AM
What if the data is from table from database.. ?.. Semester value is selected from dropdowlist value.
Naveen KumarPosted Jul 14, 2024, 4:22 AM
Hi Hazel Mahmud,
You can use aggregation with CASE statement to get your expected outut without using PIVOT. Please check the below script.
For 1st Look:
For 2nd Look:
Also, the #Test create table script has sytax issue on the column Test Name, correct it to Test_Name.