Operand type clash: text is incompatible with uniqueidentifier

Travesty3

I've seen similar error messages, but most have to do with comparing int or float to uniqueidenifier, which makes sense why you'd get an error. My error is this:

SQLSTATE[22018]: Invalid character value for cast specification: 206 [Microsoft][SQL Server Native Client 11.0][SQL Server]Operand type clash: text is incompatible with uniqueidentifier (SQLExecute[206] at /usr/src/php-5.4.8/ext/pdo_odbc/odbc_stmt.c:254)

I'm building a PHP ZF2 application and attempting to call a user-defined function with parameters. The first four parameters are UNIQUEIDENTIFIER values. The last four are BIT values. Here is my code:

public function getCustomerInspectionDocuments($fkCustomer) {
    /** @var \Zend\Db\ResultSet\ResultSet $result */
    $result = $adapter->query("
        SELECT
            createUser.FullName AS CreateUser,
            udf.CreateTime,
            udf.CompleteTime,
            modifyUser.FullName AS ModifyUser,
            udf.ModifyTime,
            udf.Source,
            udf.id AS InstanceID
        FROM
            udfDocumentInstances(
                :fkCustomer,
                :fkDocumentQueue,
                :fkDocumentType,
                :fkADUser,
                :Completed,
                :Deleted,
                :LinkByXXX,
                :LinkByOwnership
            ) udf
            LEFT JOIN ADUser createUser
                ON udf.fkCreateUser = createUser.pkid
            LEFT JOIN ADUser deleteUser
                ON udf.fkDeleteUser = deleteUser.pkid
            LEFT JOIN ADUser modifyUser
                ON udf.fkModifyUser = modifyUser.pkid
        ORDER BY
            ModifyTime DESC
    ", array(
        ':fkCustomer' => $fkCustomer,
        ':fkDocumentQueue' => '57B5829B-3EAE-46FF-8130-8A432176DE2A',
        ':fkDocumentType' => '7E5D5187-B38A-E211-B52D-0F1256A21434',
        ':fkADUser' => null,
        ':Completed' => null,
        ':Deleted' => 0,
        ':LinkByXXX' => 0,
        ':LinkByOwnership' => 0,
    ));

    // do some other stuff and return the records
}

This code works absolutely fine when executed against SQL Server 2012, but when I switch it back to 2008, it chokes with that error message. I'm using the same driver, so the only thing that changes is the server.

The problem seems to be a combination of the fact it's executed against a UDF and that I'm binding the parameters via PDO. If I change it to a simple SELECT query (from a normal table), it works. Or if I put the parameter values directly into the query, that also works. But I need to call this UDF, and I would prefer to use the parameterized query.

Is there a way to see exactly what is being sent to the SQL Server (i.e. the completely assembled query)? Or is it possible that it's passed to the server as a parameterized query and it's the SQL Server that's assembling it?

Travesty3

Based on what I found out from SQL Profiler (thanks @davek), it looks like the query is assembled on the SQL Server side, and PDO is passing all of the parameters as TEXT, which cannot be implicitly converted to UNIQUEIDENTIFIER or BIT. I'm not sure how to get it to pass them as CHAR by default. I'm also not sure why it doesn't cause an issue when using a parameterized query with a normal table.

Here is the temporary workaround I've come up with. It's ugly, but it works for now. Hopefully someone else can come up with a better answer.

'...
FROM
    dbo.udfDocumentInstances(
        CAST(:fkCustomer AS CHAR(36)),
        CAST(:fkDocumentQueue AS CHAR(36)),
        CAST(:fkDocumentType AS CHAR(36)),
        CAST(:fkADUser AS CHAR(36)),
        CAST(:Completed AS CHAR(1)),
        CAST(:Deleted AS CHAR(1)),
        CAST(:LinkByDEA AS CHAR(1)),
        CAST(:LinkByOwnership AS CHAR(1))
    ) udf
...'

So I'm casting the values from TEXT to CHAR, and then the SQL Server will implicitly convert them to UNIQUEIDENTIFIER or BIT.

If anyone can come up with a way to pass them as CHAR instead of TEXT, without having to explicitly cast each one, please post your response.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Operand type clash: text is incompatible with uniqueidentifier

From Dev

Operand type clash: bigint is incompatible with time

From Dev

Operand type clash geography is incompatible with float

From Dev

Operand type clash: date is incompatible with int in dateadd

From Dev

Tsql Operand type clash: date is incompatible with int

From Dev

Operand type clash: nvarchar is incompatible with Type_WP_Days

From Dev

Operand type clash: nvarchar is incompatible with Type_WP_Days

From Dev

Sql Server Operand type clash: date is incompatible with int

From Dev

Getting error:Operand type clash: nvarchar is incompatible with image

From Dev

Sql Server Operand type clash: date is incompatible with int

From Dev

c# Operand type clash: date is incompatible with int

From Dev

Stored Procedure Operand type clash: date is incompatible with int

From Dev

NHibernate component mapping: Operand type clash: bigint is incompatible with time

From Dev

Table type parameter in a stored procedure cause operand type clash error

From Dev

Uniqueidentifier is incompatible with numeric

From Dev

Operand Data Type Clash when executing sp_help_job via VB.Net

From Dev

Acumatica - PXDBScalar uniqueidentifier is incompatible with int

From Dev

TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

From Dev

Incompatible operand types Die and Int

From Dev

operand types are incompatible ("bool (*)()" and "bool")

From Dev

Incompatible operand types between K and int Java

From Dev

incompatible operand types r.integer and int

From Dev

operator operand type mismatch

From Dev

operand type mismatch for `vpbroadcastd'

From Dev

Unsupported operand type in Python

From Dev

Bad operand type

From Dev

Type of operand of binary AND operator

From Dev

Error: "Improper operand type"

From Dev

operand type mismatch for `mov'

Related Related

  1. 1

    Operand type clash: text is incompatible with uniqueidentifier

  2. 2

    Operand type clash: bigint is incompatible with time

  3. 3

    Operand type clash geography is incompatible with float

  4. 4

    Operand type clash: date is incompatible with int in dateadd

  5. 5

    Tsql Operand type clash: date is incompatible with int

  6. 6

    Operand type clash: nvarchar is incompatible with Type_WP_Days

  7. 7

    Operand type clash: nvarchar is incompatible with Type_WP_Days

  8. 8

    Sql Server Operand type clash: date is incompatible with int

  9. 9

    Getting error:Operand type clash: nvarchar is incompatible with image

  10. 10

    Sql Server Operand type clash: date is incompatible with int

  11. 11

    c# Operand type clash: date is incompatible with int

  12. 12

    Stored Procedure Operand type clash: date is incompatible with int

  13. 13

    NHibernate component mapping: Operand type clash: bigint is incompatible with time

  14. 14

    Table type parameter in a stored procedure cause operand type clash error

  15. 15

    Uniqueidentifier is incompatible with numeric

  16. 16

    Operand Data Type Clash when executing sp_help_job via VB.Net

  17. 17

    Acumatica - PXDBScalar uniqueidentifier is incompatible with int

  18. 18

    TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

  19. 19

    Incompatible operand types Die and Int

  20. 20

    operand types are incompatible ("bool (*)()" and "bool")

  21. 21

    Incompatible operand types between K and int Java

  22. 22

    incompatible operand types r.integer and int

  23. 23

    operator operand type mismatch

  24. 24

    operand type mismatch for `vpbroadcastd'

  25. 25

    Unsupported operand type in Python

  26. 26

    Bad operand type

  27. 27

    Type of operand of binary AND operator

  28. 28

    Error: "Improper operand type"

  29. 29

    operand type mismatch for `mov'

HotTag

Archive