I have the following query:
SELECT
*
FROM
ARELBATIDATRANSITOVIEW
WHERE
CHAPA = 1234
AND CODEMP = 1
AND BATIDA IS NOT NULL
It picks me up like this:
COD |DATA |BATIDA |ST |SEQ_BAT
1234 |2016-12-01 00:00:00.000 |2016-12-01 10:58:00.000 |C |1
1234 |2016-12-01 00:00:00.000 |2016-12-01 13:56:00.000 |C |2
1234 |2016-12-01 00:00:00.000 |2016-12-01 16:04:00.000 |C |3
1234 |2016-12-01 00:00:00.000 |2016-12-01 21:44:00.000 |C |4
1234 |2016-12-02 00:00:00.000 |2016-12-02 10:36:00.000 |C |1
1234 |2016-12-02 00:00:00.000 |2016-12-02 14:29:00.000 |C |2
1234 |2016-12-02 00:00:00.000 |2016-12-02 16:18:00.000 |C |3
1234 |2016-12-02 00:00:00.000 |2016-12-02 21:18:00.000 |C |4
I need the return to be as follows:
COD |DATA |ST |BATIDA1 |BATIDA2 |BATIDA3 |BATIDA4
1234 |2016-12-01 00:00:00.000 |C |2016-12-01 10:58:00.000 |2016-12-01 13:56:00.000|2016-12-01 16:04:00.000|2016-12-01 21:44:00.000
1234 |2016-12-02 00:00:00.000 |C |2016-12-02 10:36:00.000 |2016-12-02 14:29:00.000|2016-12-02 16:18:00.000|2016-12-02 21:18:00.000
NOTE: What can be used as a base would be the SEQ_BAT example:
BATIDA1 =[SEQ_BAT (1)]
BATIDA2 =[SEQ_BAT (2)]
BATIDA3 =[SEQ_BAT (3)]
BATIDA4 =[SEQ_BAT (4)]
SQL SERVER 2008