Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

SQL - Simple Pivot query

Avatar of csehz
csehzFlag for Poland asked on
Microsoft SQL ServerSQL
8 Comments1 Solution126 ViewsLast Modified:
Dear Experts,

I have a simple pivot query in SQL, which works in this format:

SELECT 
	*
FROM
	(SELECT AP.LFB1.LIFNR, AP.LFB1.BUKRS FROM AP.LFB1) AS SourceTable
PIVOT (COUNT(SourceTable.LIFNR) FOR SourceTable.BUKRS IN ([DE1],[DE2])) AS CountCCs

but does not work in this one:

SELECT 
	AP.LFB1.LIFNR AS VendorNumber
FROM
	(SELECT AP.LFB1.LIFNR, AP.LFB1.BUKRS FROM AP.LFB1) AS SourceTable
PIVOT (COUNT(SourceTable.LIFNR) FOR SourceTable.BUKRS IN ([DE1],[DE2])) AS CountCCs

because of getting error message:
The multi-part identifier "AP.LFB1.LIFNR" could not be bound.

Could you please advise how that syntax should be, basically instead of all the columns with using '*', I would like to select one specified column plus the two DE1 and DE2 from the pivot.

Thanks in advance,
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers