Need a solution to display data Column wise from rows

  • I am having a problem in SQL Server where i need to display the data column wise from rows. Let me explain the problem i have a table named as tbl_AgentDowntime which contains the column names as follows

    LoginID Login_StartTime(LST) Login_EndTime(LET) login_Time(LST-LET) Total_Time

    now the data in is like this there may be many entries against one Login Person for day and i want the data column wise. for e.g. say Agent1 has 3 entries then i want the data like this

    LoginID Login_StartTime(LST)1 Login_EndTime(LET)1

    Login_StartTime(LST)2 Login_EndTime(LET)2

    Login_StartTime(LST)3 Login_EndTime(LET)3 Total_Time

  • That is not really what SQL was designed to do.

    Your best bet would be to do this in a reporting tool.

    There are possible approaches, but the SQL would be knarly and impractical.

    The more you are prepared, the less you need it.

  • gauravw (11/5/2008)


    I am having a problem in SQL Server where i need to display the data column wise from rows. Let me explain the problem i have a table named as tbl_AgentDowntime which contains the column names as follows

    LoginID Login_StartTime(LST) Login_EndTime(LET) login_Time(LST-LET) Total_Time

    now the data in is like this there may be many entries against one Login Person for day and i want the data column wise. for e.g. say Agent1 has 3 entries then i want the data like this

    LoginID Login_StartTime(LST)1 Login_EndTime(LET)1

    Login_StartTime(LST)2 Login_EndTime(LET)2

    Login_StartTime(LST)3 Login_EndTime(LET)3 Total_Time

    What if a person logs in an out, say, 50 times in one day? What do you want then?

    I agree with Andrew... at best, I'd just calc the total time and display that. If someone takes exception to the total for a given person on a given day, then list the logins vertically for that one person on that one day.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I don't see any genuine need here to translate from rows to columns. There's no reason a LoginID can't appear farthest to the left on a report, so just output all the fields here except for login_Time, and then let a reporting tool like Reporting Services or Crystal Reports provide a total by LoginID on the last line. It's completely unrealistic to think that one could fit more than 2 or 3 sets of login data going across the page, unless perhaps one is willing to go to 11x17 or other large paper sizes, but even then, 6 to 8 is still likely the maximum, depending on how small the font can be made and still be readable. Unless one is willing to adopt a FIXED number of logins across the page, and then only a single row thereof, the T-SQL gets extraordinarily complex and unwieldy, and the output starts to look like a piece of junk as opposed to a decent report. Thus I'm wondering what the ultimate objective is...

    Steve

    (aka smunson)

    :):):)

    gauravw (11/5/2008)


    I am having a problem in SQL Server where i need to display the data column wise from rows. Let me explain the problem i have a table named as tbl_AgentDowntime which contains the column names as follows

    LoginID Login_StartTime(LST) Login_EndTime(LET) login_Time(LST-LET) Total_Time

    now the data in is like this there may be many entries against one Login Person for day and i want the data column wise. for e.g. say Agent1 has 3 entries then i want the data like this

    LoginID Login_StartTime(LST)1 Login_EndTime(LET)1

    Login_StartTime(LST)2 Login_EndTime(LET)2

    Login_StartTime(LST)3 Login_EndTime(LET)3 Total_Time

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply