0

Table and date:

EntryID Empno Empname Date Receivable Status
EmpNo4 Zulfiqar Baloch 2022-05-07 15000 Received
EmpNo4 Zulfiqar Baloch 2022-04-07 15000 Received
EmpNo4 Zulfiqar Baloch 2022-03-07 15000 Received
EmpNo3 Gul Ahmed 2022-05-07 20000 Received
EmpNo3 Gul Ahmed 2022-04-07 20000 Received
EmpNo3 Gul Ahmed 2022-03-07 20000 Received
EmpNo3 Gul Ahmed 2022-02-07 20000 Received
EmpNo3 Gul Ahmed 2022-01-07 20000 Received
EmpNo4 Zulfiqar Baloch 2022-02-07 15000 Received
EmpNo4 Zulfiqar Baloch 2022-01-07 15000 Received

I have this data in a table and I want to load it in C# Datagridview as columns like EmpNo, Name, January, February, March etc Meaning one persons data be showed horizontally in month wise column. Please Help if you can.

Query I tried ?:

I tried multiple queries with that i got this result

Employee No Name Jan Feb Mar
EmpNo3 Gul Ahmed 20000
EmpNo3 Gul Ahmed 20000
EmpNo3 Gul Ahmed 20000

It creates a new row for each month I want is all the months for a person in single row.

Luuk
  • 12,245
  • 5
  • 22
  • 33
Lois Lane
  • 1
  • 1
  • 2
    The show us your attempts so which comete error message – nbk May 07 '23 at 07:54
  • Would be nice to have your table column names and your query. – bonCodigo May 07 '23 at 07:54
  • @bonCodigo Column Names are EntryID, Empno, Empname, Date, Receivable, Status and these are the queries i used "Select empno as 'Employee No',Name, Receivable as 'Feb' from 360data.salarylhr where empno = '" + this.EmpNotxt.Text + "' and Date >= '" + "2022-02-01" + "'and Date <= '" + "2022-02-28" + "'" "Select empno as 'Employee No',Name, Receivable as 'Mar' from 360data.salarylhr where empno = '" + this.EmpNotxt.Text + "' and Date >= '" + "2022-03-01" + "'and Date <= '" + "2022-03-31" + "'" – Lois Lane May 07 '23 at 08:00
  • @bonCodigo picture link of the result https://ibb.co/DkRcj1v – Lois Lane May 07 '23 at 08:10
  • Please update your question with the info in the comment. Add the table column names and query to your question. Also take a look at the [guidelines that shows how to produce a minimal example.](https://stackoverflow.com/help/minimal-reproducible-example). You may also provide a sqlfiddle or [dbfiddle](https://dbfiddle.uk) with your table schema for sql related questions. – bonCodigo May 07 '23 at 08:26
  • 1
    Does this answer your question? [Pivot table returns multiple rows with NULLs, are not grouped on one row](https://stackoverflow.com/questions/54947611/pivot-table-returns-multiple-rows-with-nulls-are-not-grouped-on-one-row) or [MySQL get multiple rows into columns](https://stackoverflow.com/questions/65980647/combine-multiple-mysql-rows-into-one-row) – Luuk May 07 '23 at 08:39
  • @Luuk i have tried this please check if you can resolve the issue of duplication of Name https://dbfiddle.uk/2GoXrlA_ – Lois Lane May 07 '23 at 14:39
  • Why are you doing `GROUP BY row_no` ? When you need a unique name in your result, do a group by Name. (see: [DBFIDDLE](https://dbfiddle.uk/1n59dHtn)) P.S. The ROW_NUMBER is useless in this, and should (or can) be removed... – Luuk May 07 '23 at 14:45

0 Answers0