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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:35:33+00:00 2026-05-11T14:35:33+00:00

I have a very high-traffic table with a char(50) field which takes part in

  • 0

I have a very high-traffic table with a char(50) field which takes part in several indexes. This char(50) field allows NULLS, and in that case a NULL value is considered to be the same as a non-NULL, zero-length string for my purposes.

I also disregard leading & trailing whitespace and, while I scrub the data before I insert it, it may also be inserted by means beyond my control.

I have a sproc that is used to copy data from one table to the main table, and it needs to be high-performance. I need to delete duplicate records before inserting the new data and I am using the method discussed in this thread to perform the deletes.

My delete statement looks like this (simplified):

delete masterTable from masterTable t     join incomingDataTable inc on     (         LTRIM(RTRIM(COALESCE(inc.TextField,''))) =               LTRIM(RTRIM(COALESCE(t.TextField,'')))     ) where LTRIM(RTRIM(COALESCE(t.TextField,''))) <> ''   

I have read that constructs like LTRIM(RTRIM(…)) are bad. Can my delete statement be improved, and if so, how?

EDIT: Just to clarify, TextField does take part in indexes on both tables. EDIT2: TextField is defined as char(50) in both tables. It is not of type TEXT.

  • 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. 2026-05-11T14:35:33+00:00Added an answer on May 11, 2026 at 2:35 pm

    It is bad because your JOIN will have to scan the whole index, this is because your condition is not SARGable

    Are you also sure is is a TEXT datatype? Last I checked you could not use LTRIM or RTRIM against a Text datatype column?

    in response to the char against varchar comment, run this

    declare @v varchar(50),@v2 char(50) select @v ='a',@v2 = 'a'  select datalength(@v),datalength(@v2) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sparse matrix A of very high dimension around 30000x30000 . And
Right now I have a very high volume of requests coming to my webserver
On a site that receives a very high amount of traffic some small percent
Lets say I have a session table like this: [Session] ------- Id: int UserId:
I'm currently working on a high-traffic online search site. They have various changes they
At times I have very high memcache current connections - how can I tell
Hi I have been playing around with MDX and need some very high-level getting-started
I'm working on a rather tricky problem. At the very high level, I have
I've got a very high resolution image which is meant to be displayed on
I need to have very high-performance loop going over large datasets. I need to

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.