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 8910581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:43:29+00:00 2026-06-15T03:43:29+00:00

The following tsql fails: IF OBJECT_ID(‘FDSCorp.XLFILES’) IS NOT NULL BEGIN DELETE FROM FDSCorp.XLFILES; INSERT

  • 0

The following tsql fails:

IF OBJECT_ID('FDSCorp.XLFILES') IS NOT NULL
BEGIN 
    DELETE FROM FDSCorp.XLFILES;

    INSERT INTO FDSCorp.XLFILES 
       SELECT DISTINCT * FROM dbo.XLFILES;
END
ELSE 
    exec sp_changeobjectowner XLFILES, FDSCorp;

Error:

The image data type cannot be selected as DISTINCT because it is not comparable.

Yes XLFilES has an image column, but in this case FDSCorp.XLFILES doesn’t exist so that distinct code would never get to run.

This code is generated for each table in the database and I know that this section of the code will never be run on a table where it could fail due to the distinct issue.

I really don’t want to have to overcomplicate the code checking for types which I can’t use distinct with if that scenario could never happen in a real situation.

Is there some way I can bypass this check?

  • 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-06-15T03:43:30+00:00Added an answer on June 15, 2026 at 3:43 am

    The only way to avoid the error is for you to prevent the server from “seeing” the code you don’t want it to compile. Each batch is compiled entirely (including every statement, ignoring control flow) before execution starts:

    IF OBJECT_ID('FDSCorp.XLFILES') IS NOT NULL
    BEGIN 
        DELETE FROM FDSCorp.XLFILES;
    
        exec sp_executesql N'INSERT INTO FDSCorp.XLFILES 
           SELECT DISTINCT * FROM dbo.XLFILES;';
    END
    ELSE 
        exec sp_changeobjectowner XLFILES, FDSCorp;
    

    Now, when this batch is compiled, it won’t attempt to compile the INSERT, since so far as this batch is concerned, it’s just a string literal.

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

Sidebar

Related Questions

Considering the following TSQL: INSERT INTO Address(Street1, City, State, ZipCode) SELECT Street1, City, StateCode,
I have the following TSQL Statement: SELECT ProductId, OwnerId FROM Product How I can
Consider the following pseudo-tsql table a { field1 int, field2 int NULL } table
I have the following SQL insert statement. insert into [dbo].[Lookup] (XMLField) select '<root>' +
Consider the following tsql... create function dbo.wtfunc(@s varchar(50)) returns varchar(10) begin return left(@s, 2);
I extracted the following snippet from Profiler (from a statement that fails due to
I have the following TSQL query: SELECT DISTINCT MyTable1.Date FROM MyTable1 INNER JOIN MyTable2
I have the following TSQL where I'm trying to meaningfully supply the details of
I have following tsql code in sql server 2008: declare @ID INT SET @ID
Can anyone tell me if writing a query in the following tsql syntax is

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.