SQL Server database Pivot Table -


i have 2 tables tbl_evidence , tbl_test_result.

i want eve_id column using pivot. problem need distinct id table creating multiple rows same id , putting null value other column.

declare @sqlquery nvarchar(max) declare @pivotcolumns nvarchar(max)  --get unique values of pivot column   select        @pivotcolumns= coalesce(@pivotcolumns + ',','') + quotename(eve_id)      (select distinct eve_id       [dbo].[tbl_evidence]       cls_id=13) evidence  select @pivotcolumns  set @sqlquery =  'select reg_id, '+   @pivotcolumns + 'from tbl_evidence join tbl_test_result on tbl_evidence.eve_id= tbl_test_result.test_id      pivot( max(test_marks) eve_id in (' + @pivotcolumns +')) p cls_id=13 order reg_id'  exec sp_executesql @sqlquery 

[![the result getting null values][1]][1]

reg_id  6   13  14  27   33    37    45   48    50 ---------------------------------------------------- 979    null null 9  null null  null  null null  null 

i want result like

reg_id  6   13  14  27  33  37  45  48  50 --------------------------------------------     979     18  18  9   16  6   36  18  15  0 


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -