Torna al Thread

USE [Utenti] GO /****** Object: StoredProcedure [dbo].[PivotIncrociato] Script Date: 05/29/2010 11:01:39 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[PivotIncrociato] AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @Elementi varchar(max) set @Elementi=''; --Creazione di soli valori utili with col as ( select distinct data from orari ) --creazione di stringa valori utilizzabili select @Elementi = @Elementi + data + ',' from col; --Eliminazione ultima virgola che darebbe errore set @Elementi = substring(@Elementi, 1, len(@Elementi)-1); declare @q nvarchar(max); set @q = ' SELECT cognome ,' + @Elementi + ' from (select cognome,nome,data,orario from VistaPersOrari) as up pivot(max(orario) for data in (' + @Elementi + ')) as ppp ' EXEC @q; END
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5