Hi,
Your query seems to be not correct "select * from DEGREE_STUDENT UNION select * from JUNIOR_STUDENT where UID UNION select * from PAYMENT where STUD_UID =@UID"
You have to use the Join query to get the result of student.
here i have make sample Table and Join query for your result check with this.
CREATE TABLE [dbo].[Students](
[STUD_UID] [int] NULL,
[NAME] [varchar](50) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[DEGREE_STUDENT](
[DEG_ID] [int] NULL,
[STUD_UID] [int] NULL,
[NAME] [varchar](50) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[JUNIOR_STUDENT](
[JUN_ID] [int] NULL,
[STUD_UID] [int] NULL,
[NAME] [varchar](50) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[PAYMENT](
[PAY_ID] [int] NULL,
[STUD_UID] [int] NULL,
[Amount] [varchar](50) NULL
) ON [PRIMARY]
INSERT INTO [Students]
([STUD_UID]
,[NAME])
VALUES
(1
,'Test1')
INSERT INTO [Students]
([STUD_UID]
,[NAME])
VALUES
(2
,'Test2')
INSERT INTO [Students]
([STUD_UID]
,[NAME])
VALUES
(3
,'Test3')
INSERT INTO [JUNIOR_STUDENT]
([JUN_ID]
,[STUD_UID]
,[NAME])
VALUES
(1 ,1 ,'Junior')
INSERT INTO [JUNIOR_STUDENT]
([JUN_ID]
,[STUD_UID]
,[NAME])
VALUES
(2 ,2 ,'Junior')
INSERT INTO [DEGREE_STUDENT]
([DEG_ID]
,[STUD_UID]
,[NAME])
VALUES
(1
,3
,'Degree')
INSERT INTO [PAYMENT]
([PAY_ID]
,[STUD_UID]
,[Amount])
VALUES
(1 ,1 ,5000)
INSERT INTO [PAYMENT]
([PAY_ID]
,[STUD_UID]
,[Amount])
VALUES
(2 ,2 ,7000)
INSERT INTO [PAYMENT]
([PAY_ID]
,[STUD_UID]
,[Amount])
VALUES
(3 ,3 ,12000)
select * from Students
Select * from junior_student
select * from DEgree_student
select * from payment
Select S.STUD_UID
,S.NAME
,Case WHEN J.Name IS NOT NULL THEN J.Name ELSE D.NAME END as STUDENT_TYPE
,P.Amount
FROM
Students as S
LEFT OUTER JOIN junior_student as J ON S.STUD_UID=J.STUD_UID
LEFT OUTER JOIN DEgree_student as D ON S.STUD_UID=D.STUD_UID
LEFT OUTER JOIN payment as P ON S.STUD_UID=P.STUD_UID
WHERE
S.STUD_UID=1