decrypt and concatenate strings in select

  • I want to do this:

    SELECT (CAST(DecryptByKey(LastName) AS NVARCHAR(200)) AS LastName + ', ' + CAST(DecryptByKey(FirstName) AS NVARCHAR(200)) AS FirstName) AS Name

    I've tried many variations of this but I usually get the error :

    The data types varbinary and varchar are incompatible in the add operator.

    or sometimes - Syntax error near AS.

    So how do you do this? (SQL Server 2014)

    Doug

  • Removing the 'As Lastname' and 'AS Firstname' words should fix it

  • I've tried this before and just tried again, but I still get the same error - The data types varbinary and varchar are incompatible in the add operator.

  • Apologies. You were right. It works correctly now.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply