0

Here in that pivot query i dont want to show max(amount) i want to show only amount so when i wrote only amount this shows an error

Incorrect syntax near the keyword 'for'.

    select employeeid,[56],[8]
from 
(select fs.employeeid,
fd.Code,
fd.Amount from fs_table1 fs
inner join fs_table2 fd on fs.sIndex=fd.sIndex
 where fs.comid in (813,814)
 and fd.Code in (56,8) 
) p 
pivot
(max(Amount) for code in ([56],[8])) as pb
order by employeeid

any solutions

see sharp
  • 79
  • 1
  • 1
  • 9
  • The `PIVOT` needs an aggregate to pivot on. So when you removed `MAX(Amount)` and just had `Amount`, that caused the syntax error. See link...https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx – SS_DBA Oct 06 '17 at 13:04

1 Answers1

0

The PIVOT function requires an aggregation to get it to work

Hope this below links will clear your question.

Pivot rows to columns without aggregate

How to create a pivot query in sql server without aggregate function

Mahesh.K
  • 901
  • 6
  • 15