SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


cross tab query


cross tab query

Author
Message
imfairozkhan
imfairozkhan
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 70
Hi All,
I have a below table structure
cpr attendance_Date attendance_Time Trans_Type
123 20-Aug-13 8:8:10 I
123 20-Aug-13 6:10:10 O
123 21-Aug-13 8:10:10 I
123 21-Aug-13 7:8:10 O
123 22-Aug-13 5:5:10 O

expected output

cpr attendance_date trans_type
123 20-Aug-13 In Out
123 21-Aug-13 In Out
123 22-Aug-13 Null Out

any help is highly appreciated.

regards
Stefan_G
Stefan_G
SSC-Addicted
SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)

Group: General Forum Members
Points: 495 Visits: 960
Something like this perhaps:


select
cpr,
attendance_date,
trans_in = max(case when trans_type='I' then 'In' end),
trans_out = max(case when trans_type='O' then 'Out' end),
from Table
group by cpr, attendance_date


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search