sql case 字段整合

create procedure [dbo].[p_dm_GetBedByRID2] ( @Room_ID bigint ) AS BEGIN select convert(nvarchar(10),bed.BedNumber)+N'('+ (case when exists(select 1 from dmStudentInfo where Student_ID=bed.Student_ID) then (select StudentName from dmStudentInfo where Student_ID=bed.Student_ID) else '空' end)+N')' as BedNumber,BedInfo_ID from dmBedInfo as bed where Room_ID=@Room_ID END

sql case 字段整合_第1张图片

你可能感兴趣的:(sql,case)