LPRUN and Powershell and CSV!

I have this working fine in Powershell:

lprun -format=csv E:\Outbox\linq.linq > E:\Outbox\test.csv

The script runs a SQL query and dumps the output to a csv file.

When I open the csv file, though, all the data is in one column. How can I output the data so that it actually pus it into columns?

Thanks.

Comments

  • I don't think it's possible to understand your problem from your description.

    If I run the following with powershell 5 and linqpad 5:
    PS > "<Query Kind=`"Expression`" />`n`nnew[] { new {col1=`"a`",col2=`"b`"},new {col1=`"c`",col2=`"d`"}}" | sc test.linq
    PS > lprun -format=csv test.linq > test.csv
    PS > gc test.csv
    This is the the output I see:
    col1,col2
    a,b
    c,d
    As you can see there are two columns here.

    Can you describe exactly what you are doing, what you are expecting to see and what you are seeing. A minimal repro would also help, otherwise it's almost impossible to guess what you are omitting.
  • Hi,

    Thanks for the reply. My linq file contains one very simple piece of sql SQL: SELECT CA, CB, CC, CD FROM dbo.SomeTableWithData

    When I run it in powershell (as in my first post), the data from all columns is in one column. Looking at your example makes me think I have omitted a step?

  • jfrjfr
    edited January 24
    Dear Aquatarkus,
    I had a similar problem. I wanted to process the result of my sql query in powershell.

    This is how it works for me:
    
    # create file with result of query 
    lprun.exe mySQLQuery.linq > test.json
    
    # with powershell convert it into powershell object(s)
    $linqresult = Get-Content -Raw -Path test.json | ConvertFrom-Json
    
    # process results by object
    foreach ($Obj in $linqresult) {
       # do something with $Obj 
    }
    Of course you can pipe it out to normal csv with

    $linqresult | ConvertTo-Csv | Set-Content myFile.csv

    I'd like to do it out of the box with lprune, but sadly I was not able to do it. The switches for format do not have any effect to my results. So maybe the powershell approach helps you.

    Best regards,
    Jochen


  • jfrjfr
    edited January 24
    Dear Aquatarkus,

    Of course you can pipe it out to normal csv with

    $linqresult | ConvertTo-Csv | Set-Content myFile.csv

    I'd like to do it out of the box with lprune, but sadly I was not able to do it. The switches for format do not have any effect to my results. So maybe the powershell approach helps you.

    Best regards,
    Jochen
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!