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

  • Home
  • SEARCH
  • 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 6090897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:15:58+00:00 2026-05-23T12:15:58+00:00

I came across a misleading error in SQL Server 2008 and I wonder if

  • 0

I came across a misleading error in SQL Server 2008 and I wonder if anyone can explain what’s happening to me?

I have a stored procedure something like this:

declare @cross_reference table (
      context    varchar(20)    not null
    , value1     varchar(10)    not null
    , value2     varchar(10)    not null
)

insert into @cross_reference values ('map', 'from_value', 'to_value')
insert into @cross_reference values ('map', 'from_value', 'to_value')
insert into @cross_reference values ('map', 'from_value_xxxxx', 'to_value_xxxxxxx')

select 
    t1.field1
    , t1.field2
    , xref.value2
from table_1 t1
inner join table_2 t2 on t2.id = t1.id
left join @cross_reference xref on xref.context = 'map' and xref.value1 = t2.map_id 

The actual stored proc is more complex but this is the gist.

Upon running the SP I get a load of output rows before it errors on “string or binary data would be truncated”. The specific line references in the error pointed to somewhere in the main SELECT statement above, but after debugging a while, I found the values I was putting in the cross reference at the start were too large and that fixed it.

But my questions are:

  • how was SQL Server executing the main SELECT statement without having finishing inserting the cross reference rows? Is there some sort of deferred processing? Lazy loading of table variables?

  • Why on earth do “string or binary data would be truncated” message not point to where it is actually happening? Or am I doing it wrong?

Thanks,
Ray

EDIT

I think it must be something to do with the LEFT JOIN to the table variable and that none of its columns are involved in the WHERE clause. SQL Server seems to have left the preparation of the table until it’s needed (after the INNER JOINs are complete) and at that point errored when it already has the majority of the result set ready to SELECT.

I’ve noticed too that the values that are successfully INSERTed into @cross_reference do show in the result set that’s returned. Whereas the rows that failed to insert for being too big just show NULL.

  • 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-23T12:15:59+00:00Added an answer on May 23, 2026 at 12:15 pm

    Just because an error has occurred, that doesn’t stop the stored proc from progressing. You won’t see the error message because by default, SSMS shows the result grid until the query has finished processing.

    This shows results for 10 seconds before switching to the error message:

    RAISERROR('Error',16,1)
    select top 1000 * from sys.objects so1,sys.objects so2,sys.objects so3
    WAITFOR DELAY '00:00:10'
    

    If you want the stored proc to exit early if an error occurs, you have to bail out early. You could re-write your insert to be something like:

    declare @cross_reference table (
          context    varchar(20)    not null
        , value1     varchar(10)    not null
        , value2     varchar(10)    not null
    )
    
    insert into @cross_reference (context,value1,value2)
    values ('map', 'from_value', 'to_value'),
           ('map', 'from_value', 'to_value'),
           ('map', 'from_value_xxxxx', 'to_value_xxxxxxx');
    if @@ERROR !=0 or @@ROWCOUNT !=3 return
    

    Or if you don’t know the row count, change the condition to @@ROWCOUNT = 0

    (Or, of course, use TRY/CATCH – but I’ve not written much code using them myself yet, so can’t just knock out an example)

    Your current code has made each insert independent – so those inserts that can work, do, and those that cannot, produce error messages. Then it carries on with processing your final query. Because the table is used in a LEFT JOIN, of course it doesn’t matter to the final query whether any rows exist in the table variable.

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

Sidebar

Related Questions

Came across this error today. Wondering if anyone can tell me what it means:
Came across something strange while migrating to my new server. I have a script
I came across this recently, up until now I have been happily overriding the
I came across this class while reading a C# book and have some questions.
I came across this article written by Andrei Alexandrescu and Petru Marginean many years
I came across a printed article by Bertrand Meyer where he states that tests
I came across a controller in an older set of code (Rails 1.2.3) that
I came across an article about Car remote entry system at http://auto.howstuffworks.com/remote-entry2.htm In the
I came across the function InterlockedExchange and was wondering when I should use this
I came across this snippet of code on MSDN: entityBuilder.Metadata = @res://*/AdventureWorksModel.csdl| res://*/AdventureWorksModel.ssdl| res://*/AdventureWorksModel.msl;

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.