November 7, 2016 at 9:20 am
Let's suppose I have $objTable, a SQL Server table object, with 3 columns:
nUnitType_Id
cE_Descritpion
cF_Description
I swear that at one point a few months ago, this bit of code was returning $DescCols containing the expected 2 columns, but for the life of me I can't get it to work now... What am I missing here?
$DescCols = $objTable.Columns | ?{(($_.Name).Substring(0, 3) -like "c[EF]_*") `
-and ((group ($_.Name).Substring(3)).Count -eq 2)}
$DescCols
Thanks!
November 8, 2016 at 11:28 am
Figured it out.
$DescCols = @()
$MultiCols = $objTable.Columns | %{$_.Name.Substring(3)} | group | ?{$_.Count -eq 2}
if ($MultiCols)
{
foreach ($Row in $MultiCols)
{
$DescCols += $objTable.Columns | ?{$_.Name -like "*$($Row.Name)"} | select name
}
}
November 8, 2016 at 1:15 pm
Thanks for posting the answer you found for yourself. That may help someone someday.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy