Featured post
SQL Dynamic Column Query -
possible duplicate:
is there way create sql server function "join" multiple rows subquery single delimited field?
i have table of "events", , each event has a list of 1-4 (essentially variable #) "users". let's events today, , want list users dynamic number of columns, rather repeated rows.
right have
select e.eventid, e.time, u.name events inner join users u on e.userid = u.userid date = '12/20/2010'
this brings me results like:
eventid, time, name 211, '4:00am', 'joe' 211, '4:00am', 'phil' 211, "4:00am', 'billy' 218, '7:00am', 'sally' 218, '7:00am', 'susan'
i can work , it's acceptable, duplication eventid , time (there more columns in actual query) seems wasteful me. in output this:
eventid, time, name1, name2, name3 211, '4:00am', 'joe', 'phil', 'billy' 218, '7:00am', 'sally', 'susan', null
i have tried looking @ tutorials pivots (i have sql 2008), don't know if conceptually match i'm trying do. of them using "min" or "max".
maybe can't done? other alternative list of events today, , loop through that, finding recordset of users event. prefer grab in 1 query though.
any ideas?
returning variable number of columns harder deal in code. result set getting easy transform object can worth in code.
what trying output?
- Get link
- X
- Other Apps
Comments
Post a Comment