I am running the below powershell script to export some data into a text file:$DBName = 'MYDB'#$Srv = '$(ESCAPE_SQUOTE(SRVR))'$Srv = 'MYServer\MyInstance'SL SQLSERVER:\SQL\"$Srv"\Databases\"$DBName"\Tables$bcpconn = '-T'
$DBName = 'MYDB'#$Srv = '$(ESCAPE_SQUOTE(SRVR))'$Srv = 'MYServer\MyInstance'SL SQLSERVER:\SQL\"$Srv"\Databases\"$DBName"\Tables$bcpconn = '-T'
$IDColumn = 'MyID'
$TableName = 'MyTable'$ParentTable = 'MyParentTable'
$Query = '"select * from ' + $DBName + '.dbo.' + $TableName + ' WHERE ' + $IDColumn + ' IN (SELECT ' + $IDColumn + ' FROM ' + $DBName + '.dbo.' + $ParentTable + ' WHERE $Partition.WBC_' + $ParentTable + '_pf(PartitionDate) = 2)"'$Saveas = Invoke-Sqlcmd -query "SELECT [value] FROM [SupportDB].[Support].[PartitioningConfiguration] (nolock) WHERE name = 'ArchivePath' and TableName = '$TableName'"$ReplaceServername = $Srv -replace '\\', '_'$Saveas.value = $Saveas.value + $ReplaceServername + "_" + $DBName + "_" + $TableName + '.txt'bcp $Query QUERYOUT $Saveas.value -n $bcpconn -S $Srv
I get a message: "0 rows copied." and the output file is empty.
When I take the value of the $Query variable and run it in Management Studio, it returns around 150 records.
When I run:Invoke-Sqlcmd -query $Query
I get:Invoke-Sqlcmd : The identifier that starts with 'select * from MyDB.dbo.MyTable WHERE MyID IN (SELECT MyID FROM MY' is too long. Maximum length is 128.
This is a duplicate of
What is wrong with asking on two forums?
We're all volunteers here. And it can be more than a little frustrating to put in the time and effort to help someone to only find out later that they had their issue already solved elsewhere and you could have been doing something more productive and appreciated. It's just a common courtesy to give a person or group a chance to have dialog with you and perhaps solve your problem before you blast it out all over the kingdom.
Oh, and by the way, in my original post I did not tell anyone not to respond. It was informational only.
Powered by IDERA