0
SELECT CONCAT(e.c_firstName,' ',e.c_Lastname) AS NAME    ,
sum(CASE WHEN uc.c_name='ELECTRIC CHARGES' then uc.c_amount ELSE NULL END) AS Electric,
sum(CASE WHEN uc.c_name='GAS CHARGES' then uc.c_amount ELSE NULL END) AS GAS,
sum(CASE WHEN uc.c_name='FURNITURE CHARGES' then uc.c_amount ELSE NULL END) AS Furniture,
sum(CASE WHEN uc.c_name='WATER CHARGES' then uc.c_amount ELSE NULL END) AS WATER,
sum(CASE WHEN uc.c_name='TV LICENSE FEE' then uc.c_amount ELSE NULL END) AS TV_LICENSE_FEE

FROM app_fd_pr_uage_bill ub JOIN app_fd_pr_uagecateg_bil uc ON ub.id=uc.c_FrKeyUbill
JOIN  app_fd_hrm_employee e
ON ub.c_employeeName=e.id
GROUP BY Name

1:Uage bill is a table where i am entering all bills of employee.

2:uageCategory bill is a table where i created a configuration for entering names of bills.

3:hrm_employee is a table where all employee of a company has been inserted.

this query is a hard coded query but i want a dynamic query where any row will be added in uage cateogry bill it will be automatically converted into a column using this query.

Ergest Basha
  • 7,870
  • 4
  • 8
  • 28
  • You need in stored procedure with dynamic SQL. – Akina Sep 16 '21 at 08:00
  • can you ellaborate it – Ahmed Akram Sep 17 '21 at 09:18
  • Do this like in https://stackoverflow.com/a/69204421/10138734 – Akina Sep 17 '21 at 09:21
  • I have seen that type of solution before, but Group_concat function is not working in HeidSQL Server, and i have limitation not to use other servers yet to attempt this query is HeidiSQL server using mysQL. – Ahmed Akram Sep 17 '21 at 12:49
  • *Group_concat function is not working in HeidSQL Server* HeidiSQL **Server** - what is it? I know HeidiSQL, and it is a client which simply sends SQL text to the server, hence it cannot "not working". – Akina Sep 17 '21 at 18:26
  • You can also check this one - https://stackoverflow.com/questions/45704805/group-concat-is-not-a-built-in-function-heidisql – Rajeev Singh Sep 23 '21 at 05:11

0 Answers0