Windows Vista Forums

Creating files from Data Table
  1. #1


    Shadow Guest

    Creating files from Data Table

    i have an interesting need and one that i am almost there with but can't get
    the last bit.
    i am querying the database to get a results set. Within the resultset,
    there are multiple rows within a group (in other words, if i perform a
    groupby i see that there are multiple rows per group). I want to take the
    contents from this and make a new file for each group name and place the
    contents of the rows into the file. So in essense i want to create a union
    all statement into a file.

    Here is what i have thus far
    $dt | %{ni -itemType File $_.Item(0) -value $_.Item(1)}

    This takes each item and creates the file and then stuffs the contents. So
    i have something that works but it tries to create the same file over for the
    rows which have identical names.



    I have tried this
    $dt | ft sqltext -group Column1 | %{ni -itemType File $_.Item(0) -value
    $_.Item(1) -whatif}
    but since it is using the FT i don't get the contents.
    i have also tried
    $dt | group column1 | %{ni -Type File $_.Name -value $_.Values}
    but that doesn't quite work either.

    How can i get the contents of each item to write into the file per group?

      My System SpecsSystem Spec

  2. #2


    Shadow Guest

    RE: Creating files from Data Table

    I solved this soon after i posted it. I guess persistance kicked in for me
    (and the fact that i just had a Mocha with 4 shots of espresso)
    $dt | group Column1 | %{ni -type File $_.Name -value ( $_.Group |
    %{$_.SQLText})}

    "Shadow" wrote:

    > i have an interesting need and one that i am almost there with but can't get
    > the last bit.
    > i am querying the database to get a results set. Within the resultset,
    > there are multiple rows within a group (in other words, if i perform a
    > groupby i see that there are multiple rows per group). I want to take the
    > contents from this and make a new file for each group name and place the
    > contents of the rows into the file. So in essense i want to create a union
    > all statement into a file.
    >
    > Here is what i have thus far
    > $dt | %{ni -itemType File $_.Item(0) -value $_.Item(1)}
    >
    > This takes each item and creates the file and then stuffs the contents. So
    > i have something that works but it tries to create the same file over for the
    > rows which have identical names.
    >
    > I have tried this
    > $dt | ft sqltext -group Column1 | %{ni -itemType File $_.Item(0) -value
    > $_.Item(1) -whatif}
    > but since it is using the FT i don't get the contents.
    > i have also tried
    > $dt | group column1 | %{ni -Type File $_.Name -value $_.Values}
    > but that doesn't quite work either.
    >
    > How can i get the contents of each item to write into the file per group?


      My System SpecsSystem Spec

Creating files from Data Table problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert Table Data to CSV? Mihail Stacanov PowerShell 2 22 Dec 2009
Goofed up GPT partition table... Data Lost? __ Vista General 0 20 Jul 2008
Goofed up GPT partition table... Data Lost? __ Vista file management 0 20 Jul 2008
Goofed up GPT partition table... Data Lost? __ Vista hardware & devices 0 20 Jul 2008
Adding data to a hash table NeilOz PowerShell 3 27 Dec 2007