Use varchar and uniqueidentifier to search in XML column in SQL Server

SELECT [Event_Id] 
FROM [Processing].[Event]
WHERE [RefEventTypeId] = 8
  AND [Description] LIKE '%' + (SELECT [Guid] 
                                FROM [Security].[WebUser] 
                                WHERE Login = 'test') +'%'  

When I tried use one of my select parameters with LIKE I get this error:

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

I have changed this select to some string just to check is that a problem with select and got another error:

SELECT [Event_Id] 
FROM [Processing].[Event]
WHERE [RefEventTypeId] = 8
  AND [Description] LIKE '%' + 'E522A826-C538' +'%'  

Error:

Argument data type xml is invalid for argument 1 of like function.

My Description column is of type XML. Can I get some search using LIKE? And how to use SELECT in that case if Guid that I have been searching for is uniqueidentifier?

P.S. Sorry for grammar.

Answers


First of all, keep in mind using %something% for a LIKE clause, could be very loooong. Your query should be something like this:

SELECT [Event_Id] 
FROM [Processing].[Event]
WHERE [RefEventTypeId] = 8
  AND CONVERT(nvarchar(max), [Description]) LIKE '%' + (SELECT CONVERT(nvarchar(32), [Guid])
                                FROM [Security].[WebUser] 
                                WHERE Login = 'test') +'%'  

Need Your Help

What is an szone_error?

xcode memory gdb

I see this sometimes in xcode console.

Creating a JLabel with multiple lines from other text

java swing jlabel

I was creating a program to take text from a JTextArea and put it into a JLabel, but a JLabel is only one lie and the only way I know of to add multiple lines to a JLabel is to use html functions w...