Click here to Skip to main content
GO
/****** Object:  StoredProcedure [dbo].[Sp_GetReport]    Script Date: 10/09/2012 14:31:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
ALTER Proc [dbo].[Sp_GetReport] --Sp_GetReport 1
(
@ContID bigint
)
as
 
select COUNT( *)as Total,JID into #tb from tbtest where ContID=@ContID group by JID
--select * from  #tb

 
DECLARE @cols NVARCHAR(2000)
DECLARE @cols1 NVARCHAR(2000)
SELECT  @cols = COALESCE(@cols + ',[' + cast( JID as varchar(20)) + ']','[' +cast( JID as varchar(20)) + ']')
FROM    #tb
 
SELECT  @cols1 = COALESCE(@cols1 + ',[' + cast( JID as varchar(20)) + '] as J'+ cast( JID as varchar(20)) ,'[' +cast( JID as varchar(20)) + '] as J'+ cast( JID as varchar(20)) )
FROM    #tb
ORDER BY JID
 
--select @cols as Jdetail
drop table #tb
exec ('SELECT ComID,ContID, '+@cols1+' FROM  (SELECT ComID,ContID, JID, Point FROM tbtest ) ps PIVOT (MAX(point) FOR JID IN (  '+@cols+' )) AS pvt')
--select * from @cols1
--Sp_GetReport 1
Closed because This post is not a question, or has not been phrased in a way that allows a reasonable answer to be provided. Reported by Wes Aday, Sergey Alexandrovich Kryukov, aspnet -i on Tuesday, October 9, 2012 8:47am.
Posted 8-Oct-12 23:05pm
Edited 9-Oct-12 0:19am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 330
1 OriginalGriff 285
2 Sergey Alexandrovich Kryukov 274
3 BillWoodruff 170
4 Aescleal 140


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100