0

My Table:

| code_client| tel_client  | name_client  |
|:-----------|-------------|-------------:|
| 1          |  22415671   |     Roffus   |
| 1          |  22114511   |     Roffus   |
| 1          |  52421671   |     Roffus   |
| 1          |  99415671   |     Roffus   |
| 4          |  91512371   |     Mylon    |
| 4          |  85673221   |     Mylon    |
| 99         |  56732671   |     Alfly    |
| 99         |  92347671   |     Alfly    |
| 77         |  45445671   |     Nerthit  |
| 65         |  32354111   |     Brumos   |

What i want:

| code_client|tel_client_1|tel_client_2|tel_client_3|tel_client_4|
|:-----------|------------|------------|------------|-----------:|
| 1          |  22415671  | 22114511   | 52421671   | 99415671   |
| 4          |  91512371  | 85673221   |            |            |
| 99         |  56732671  | 92347671   |            |            |
| 77         |  45445671  |            |            |            |
| 65         |  32354111  |            |            |            |

In second table i need a code_client column and a max value of phone column by client with highest number of telephone.

How make this with dynamic sql?

  • Dynamic SQL simply means that you build the SQL statement dynamically. That can be in any language, e.g. C# or PHP. Select all client codes from the table (`select distinct code_client from mytable`) and then use the result to build your final query in a loop. (You can of course just as well select the data as is and put the values in a grid/table in your application without having to write a pivot query.) – Thorsten Kettner May 23 '17 at 14:59

0 Answers0