with cte (Dia,Cliente,Estab,Nome,Maquina)as(select (case when dia in(1,8,15,22) then '2ª Feira' when dia in(2,9,16,23) then '3ª Feira' when dia in(3,10,17,24) then '4ª Feira' when dia in(4,11,18,25) then '5ª Feira' when dia in(5,12,19,26) then '6ª Feira' when dia in(6,13,20,27) then 'Sabado' when dia in(7,14,21,28) then 'Domingo' else '' end) as dia,rotl.Cli_Cod,rotl.Cli_Estab,cli.nome,isnull(maq.cod,0)as Maquina from RotCinner join rotd on RotD.RotC_Id=rotc.idinner join rotl on rotl.RotD_ID=rotd.idinner join cli on cli.cod=RotL.Cli_Cod and cli.Estab=rotl.Cli_Estableft join maq on maq.Cli_Cod=cli.cod and cli.estab=maq.Cli_Estabwhere rotc.Vnd_Cod=28and rotc.Ativa=1and maq.Ativa=1group by rotd.Dia,rotl.Cli_Cod,rotl.Cli_Estab,cli.nome,maq.cod)select dia,maquinafrom cte
Help SQL Query Pivot CTE
in SQL
Posted · Edited by cosmicsnake
Hi, I have this query
And i have this result:
But i want this:
How can i resolve my problem?
Regards