Jump to content
Fórum Script Brasil
  • 0

PIVOT - SQL Server


CamilinhaK
 Share

Question

Pessoal,

Boa tarde!

 

Estou tentando usar o comando "pivot" no SQL, mas estou encontrando dificuldades. Queria saber se vocês podem me dar uma ajuda.

A ideia é transformar as linhas e uma base em colunas. Então o meu programa está da seguinte forma:

SELECT BASE_INICIAL.CC,

[000000002814] as Prod1,

[2815] as Prod2,

[000000002816] as Prod3,

[000000002817] as Prod4

FROM (SELECT DISTINCT LV.CC, LVP.CB

FROM P INNER JOIN (LVP INNER JOIN LV ON LVP.T = LV.T) ON P.PROD = LVP.PROD

WHERE P.GRIFE IN ('RES', 'BALAS','RESMI','BEB','PENTA', '406','ARI')

AND P.COL IN ('01', '25')

AND LVP.DTV > '01/01/2014'

GROUP BY LV.CC, LVP.CB) as BASE_INICIAL

PIVOT (COUNT(BASE_INICIAL.CC)

FOR BASE_INICIAL.CB IN (

[000000002814],

[2815],

[000000002816],

[000000002817] )) as BASE_FINAL;

 

No entanto o programa diz: "The multi-part identifier "BASE_INICIAL.CC" could not be bound", se referindo ao primeiro BASE_INICIAL.CC, logo ao lado do primeiro select.

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.1k
×
×
  • Create New...