Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6747329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:25:45+00:00 2026-05-26T12:25:45+00:00

I have a long stored procedure and when I execute the procedure I get

  • 0

I have a long stored procedure and when I execute the procedure I get the following error:

Msg 206, Level 16, State 2, Line 1
Operand type clash: varchar(max) is incompatible with sql_variant

So to trouble shoot I have printed satetement where the problem is and the code is:

SELECT  'Name' ,
                7 ,
                CASE WHEN 'varchar' = 'varbinary'
                     THEN REPLACE(UPPER(sys.fn_sqlvarbasetostr([Name])), 'X', 'x')
                     ELSE CONVERT(VARCHAR(4000), [Name])
                END , 'varchar'
        FROM    ref.dbo.datatables
        WHERE   id = 12
        ORDER BY [ID]

So When I execute the above statement it is givng me the error as:

Msg 206, Level 16, State 2, Line 1
Operand type clash: varchar(max) is incompatible with sql_variant

The datatype of Name is Varchar(MAX) in ref.dbo.datatables table

How to solve this issue?

Answer:

This is what I did to work:

SELECT 'Name',
        7,
        CASE WHEN 'varchar' = 'varbinary'
        THEN REPLACE(UPPER(sys.fn_sqlvarbasetostr(CONVERT(VARBINARY,[Name]))),'X','x')
        ELSE CONVERT(VARCHAR(4000),[Name])
        END,
        'varchar'
FROM ref.dbo.datatables
WHERE id = 12
ORDER BY [ID]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:25:45+00:00Added an answer on May 26, 2026 at 12:25 pm

    The error is correct, you can’t implicitly (or explicitly) cast a VARCHAR(MAX) to sql_variant. If Name is a VARCHAR(MAX) you will need to convert it to a compatible type (like VARCHAR(8000) in order to pass it in as a parameter to sys.fn_sqlvarbasetostr()

    see msdn:

    sql_variant objects can hold data of any SQL Server data type except text, ntext, image, varchar(max), nvarchar(max), varbinary(max), xml, timestamp, and Microsoft .NET Framework common language runtime (CLR) user-defined types. An instance of sql_variant data also cannot have sql_variant as its underlying base data type.

    If you need the functionality of sys.fn_sqlvarbasetostr() and can’t down convert your col without losing data, you may need to roll your own version of that function. CLR would be a good bet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in a very long stored procedure, where P equals
I have a very long-running stored procedure in SQL Server 2005 that I'm trying
I have a somewhat-long-running stored procedure being called from a PB application. I want
I have a long stored procedure that does a lot of querying and generates
So basically I have this relatively long stored procedure. The basic execution flow is
I have a long list of SPs (stored procedure) and Functions in my SQL
I have a stored procedure which used the EXECUTE IMMEDIATE command to execute a
I have an issue with the below stored procedure. It runs fine as long
I have a stored procedure that returns hierarchical data in a single long row,
I have the following code that executes a Stored Procedure in Sybase throught VBA.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.