DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX) select @cols = STUFF((SELECT distinct ',' + QUOTENAME(StuDocname) from StudentDocuments FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'') set @query = 'SELECT StudentCode,Stuname, ' + @cols + ' from ( select DISTINCT SC.StuCurrentId,StudentCode,upper(First_Name + '' '' + Middle_Name + '' '' + Last_Name) as Stuname ,Sd.StuDocname,SASD.IsSelected,(case when IsSelected = 1 then ''YES'' when IsSelected = 0 then ''NO'' end) as status from tbl_Student_Current SC inner join StudentAdmission SA on SC.StudentId=SA.StudentId inner join StudentAdmission_StudentDocuments SASD on SA.StudentId=SASD.StudentId left outer join StudentDocuments SD on SASD.StudentDocId=SD.StuDocId ) x pivot ( MAX(status) for StuDocname in (' + @cols + ') ) p ' execute(@query)
Declare @var as varchar(10)=null select isnull(@var,0) as Result
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)