您好我在SQL-SERVER中创建了一个视图,我还希望能够在此视图的返回结果中添加一列。
这是我的代码:
ALTER VIEW [eConnect].[GetStudentTeachers]
AS
select
srmitv.StudentId as StudentId,
srmitv.TeacherAlias as Alias,
srmitv.TeacherAvatarFileName as AvatarFileName,
srmitv.TeacherMessageUserId as MessageUserId,
srmitv.TeacherUserName as UserName,
sp.Sex as Gender,
from
StudentRegularModuleInstanceTeachersView srmitv
inner join Sync_Persons sp on srmitv.TeacherId = sp.TeacherID and sp.Deletion_Date is null
union
select
somirtv.StudentId as StudentId,
somirtv.TeacherAlias as Alias,
somirtv.TeacherAvatarFileName as AvatarFileName,
somirtv.TeacherMessageUserId as MessageUserId,
somirtv.TeacherUserName as UserName,
sp.Sex as Gender
from
dbo.StudentOlcModuleInstanceRelatedTeachersView somirtv
inner join Sync_Persons sp on somirtv.TeacherId = sp.TeacherID and sp.Deletion_Date is null
GO
现在我想在这里添加另一列RoleId,它始终具有值1.如何实现这一目标?
答案 0 :(得分:3)
只需将其添加到选择中:1 as RoleId
ALTER VIEW [eConnect].[GetStudentTeachers]
AS
select
srmitv.StudentId as StudentId,
srmitv.TeacherAlias as Alias,
srmitv.TeacherAvatarFileName as AvatarFileName,
srmitv.TeacherMessageUserId as MessageUserId,
srmitv.TeacherUserName as UserName,
sp.Sex as Gender,
1 as RoleId
from
StudentRegularModuleInstanceTeachersView srmitv
inner join Sync_Persons sp on srmitv.TeacherId = sp.TeacherID and sp.Deletion_Date is null
union
select
somirtv.StudentId as StudentId,
somirtv.TeacherAlias as Alias,
somirtv.TeacherAvatarFileName as AvatarFileName,
somirtv.TeacherMessageUserId as MessageUserId,
somirtv.TeacherUserName as UserName,
sp.Sex as Gender,
1 as RoleId
from
dbo.StudentOlcModuleInstanceRelatedTeachersView somirtv
inner join Sync_Persons sp on somirtv.TeacherId = sp.TeacherID and sp.Deletion_Date is null
GO
答案 1 :(得分:0)
不确定这是否是你想要的
SELECT 1 AS RoleID, * FROM [eConnect].[GetStudentTeachers]