marabunta
Goto Top

Powershell SQL maximal 128 Zeichen

Ich hab mit der Funktion Get-IniContent die Daten jetzt von einer externen Ini-Datei eingelesen.
Die SQL-Abfrage aus mehreren Zeilen zusammengefügt(Array) und abgefeuert.
Jetzt gefällt dem wieder was nicht, zuvor habe ich versucht alle "" und ' zu entfernen und alle SQL-Abfragezeilen in eine Zeile zu schreiben.


Ini-Datei
Query1= $("Select distinct email  from  test_db.td.test  
Query2=where IsNull (td.test.us_dom_auth,'') not like '%de%'  
Query3=and IsNull (td.test.us_dom_auth,'') not like '%De%'  
Query4=and IsNull (td.test.description,'') not like '%De%'   
Query5=and IsNull (td.test.description,'') not like '%de%'  
Query6=and email != 'NULL'")  
Das wird im Skript zusammengesetzt

$Query=
$("Select distinct email  from  test_db.td.test where IsNull (td.test.us_dom_auth,'') not like '%de%' and  
IsNull (td.test.us_dom_auth,'') not like '%De%' and IsNull (td.test.description,'') not like '%De%'  and IsNull  
(td.test.description,'') not like '%de%' and email != 'NULL'")  

$Global:QueryToServer=Invoke-Command -ComputerName $TargetServer -scriptblock ${function:SQL} -Credential $cred -ArgumentList $Query, $TargetServer, $TargetDatabase 


#--- Nach Ausführung des Skripts:

PS H:\> $QueryToServer
Error: Exception calling "Fill" with "1" argument(s): "Incorrect syntax near '$'.  
The identifier that starts with 'Select das da from test_db.td.test where IsNull (td.test.us,'') not like '%test%' and IsNull (td.' is too long. Maximum length is 128."   
PS H:\>


#------ Im Skript ohne Ini-datei funktioniert das, wenn ich die ganze Abfrage direkt in die Variable schreibe:
$Query= $("Select distinct email  from  qcsiteadmin_db.td.USERS  
where IsNull (td.users.us_dom_auth,'') not like '%deactiv%'  
and IsNull (td.users.us_dom_auth,'') not like '%Demo%'  
and IsNull (td.users.description,'') not like '%Demo%'   
and IsNull (td.users.description,'') not like '%deactiv%'  
and email != 'NULL'")  

Content-Key: 266586

Url: https://administrator.de/contentid/266586

Printed on: April 19, 2024 at 20:04 o'clock

Mitglied: 114757
114757 Mar 17, 2015 updated at 15:37:59 (UTC)
Goto Top
Das kann so nicht gehen...du fügst die Strings nicht richtig zusammen, du hast da ja Zeilenumbrüche in der $query-Variablen ... sagt ja schon die Exception

Füge dein Array mit $deinArray -join " " zu einem einzeiligen String zusammen....

Gruß jodel32