If I remember well some drivers don't handle well varchar(max) so if you have control over table definition just use varchar(8000). I tested with ODBC Driver 17 for SQL Server and works well.
#include <Debug.au3>
MsSqlQueryTest()
Func MsSqlQueryTest()
Local $sDatabase = 'master' ; change this string to YourDatabaseName
Local $sServer = '(local)' ; change this string to YourServerLocation
Local $sUser = 'sa' ; change this string to YourUserName
Local $sPassword = 'test' ; change this string to YourPassword
Local $sDriver = 'ODBC Driver 17 for SQL Server'
Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';'
Local $oConnection = ObjCreate("ADODB.Connection")
$oConnection.ConnectionString = $sConnectionString
$oConnection.Open
Local $sQuery
$sQuery &= "SET NOCOUNT ON" & @CRLF
$sQuery &= "DECLARE @MyTable TABLE (id INT, myValue varchar(8000), pdata varchar(8000))" & @CRLF
$sQuery &= "INSERT INTO @MyTable VALUES (123, '+OK', '<root><receipts><receipt><command name=" & '"REPORTDAY"' & " /></receipt></receipts></root>')" & @CRLF
$sQuery &= "SELECT id, myValue, pdata FROM @MyTable"
Local $oRecordSet = $oConnection.Execute($sQuery)
Local $array = $oRecordSet.GetRows
_DebugArrayDisplay($array)
EndFunc
Alternatively some drivers support DataTypeCompatibility in connection string, so you might give a try.
If you don't have control over table definition, you can cast data in the query:
#include <Debug.au3>
MsSqlQueryTest()
Func MsSqlQueryTest()
Local $sDatabase = 'master' ; change this string to YourDatabaseName
Local $sServer = '(local)' ; change this string to YourServerLocation
Local $sUser = 'sa' ; change this string to YourUserName
Local $sPassword = 'test' ; change this string to YourPassword
Local $sDriver = 'ODBC Driver 17 for SQL Server'
Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';'
Local $oConnection = ObjCreate("ADODB.Connection")
$oConnection.ConnectionString = $sConnectionString
$oConnection.Open
Local $sQuery
$sQuery &= "SET NOCOUNT ON" & @CRLF
$sQuery &= "DECLARE @MyTable TABLE (id INT, myValue varchar(max), pdata varchar(max))" & @CRLF
$sQuery &= "INSERT INTO @MyTable VALUES (123, '+OK', '<root><receipts><receipt><command name=" & '"REPORTDAY"' & " /></receipt></receipts></root>')" & @CRLF
$sQuery &= "SELECT id, CAST(myValue as varchar(8000)), CAST(pdata as varchar(8000)) FROM @MyTable"
Local $oRecordSet = $oConnection.Execute($sQuery)
Local $array = $oRecordSet.GetRows
_DebugArrayDisplay($array)
EndFunc