Home Forums Programming Powershell How to find number of columns returned from query in powershell RE: How to find number of columns returned from query in powershell

  • Eirikur Eiriksson (7/25/2014)


    Jeff Moden (7/25/2014)


    Chand00 (7/25/2014)


    Hi,

    Thank you. Below one worked for me.

    $QueryResults[0].Table.Columns.Count

    Apologies. I tried to post but I was unable to post somehow. Once again Thankyou

    Still, why does this need to be done from PowerShell? What is the overall task that you're trying to accomplish?

    Just to supply the T-SQL answer to the thread, the stored procedure sp_describe_first_result_set does the job.

    😎

    So does a trip to sys.all_columns or sys.columns or INFORMATION_SCHEMA.columns (to name a couple of methods).

    I still want to know why someone needs to do this from PowerShell. 😉

    --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)