Good people, I have this little SQL code:
DECLARE
@StringRTF VARCHAR(MAX),
@Posh VARCHAR(8000)
SET @StringRTF = (select traduçao from artigos where Cod_Art='01010066')
select @StringRTF
SET @Posh = 'powershell.exe -ExecutionPolicy ByPass -Command Add-Type -AssemblyName System.Windows.Forms; $Rtb = New-Object -TypeName System.Windows.Forms.RichTextBox; $stringRTF = \"' + (select @StringRTF) + '\"; $Rtb.Rtf = $stringRTF; $Retorno = $Rtb.Text; Write-Host($Retorno);'
select @Posh
EXEC master.dbo.xp_cmdshell @Posh
No select @StringRTF
returns
{\ rtf1 \ ansi \ ansicpg1252 \ deff0 \ deflang2070 {\ f0 \ fmodern \ fprq6 \ fcharset134 SimSun;} {\ f1 \ fnil \ fcharset0 MS Sans Serif;}} \ viewkind4 \ uc1 \ pard \ lang2052 \ f0 \ fs17 \ 'b7 \' f2 \ 'c8 \' cb \ 'b7 \' eb \ 'b7 \' f2 \ 'c8 \' cb6346 \ 'b8 \' f6 \ 'c4 \' b9 \ 'f0 \' bb \ 'a8 \ lang2070 \ f1 \ par}
No select @Posh
returns
powershell.exe -ExecutionPolicy ByPass -Command Add-Type -AssemblyName System.Windows.Forms; $ Rtb = New-Object -TypeName System.Windows.Forms.RichTextBox; $ stringRTF = \ "{\ rtf1 \ ansi \ ansicpg1252 \ deff0 \ deflang2070 {\ f0 \ fmodern \ fprq6 \ fcharset134 SimSun;} {\ f1 \ fnil \ fcharset0 MS Sans Serif;}} \ viewkind4 \ uc1 \ pard \ lang2052 \ f0 \ fs17 \ 'b7 \' f2 \ 'c8 \' cb \ 'b7 \' eb \ 'b7 \' f2 \ 'c8 \' cb6346 \ 'b8 \' f6 \ b5 \ 'c4 \' b9 \ 'f0 \ bb \' a8 \ lang2070 \ f1 \ par} \ "; $ Rtb.Rtf = $ stringRTF; $ Return = $ Rtb.Text; Write-Host ($ Return);
If I copy what returns in @Posh
and in% in cmd, it does what is requested
夫人 冯 夫人 6346 个 红 的 桂花
But in SQL it always gives me error and I can no longer see why.
The error that you give in SQL is:
The string is missing the terminator: ". + CategoryInfo: ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId: TerminatorExpectedAtEndOfString
What could be wrong with SET @Posh
?!