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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:10:05+00:00 2026-06-18T07:10:05+00:00

I have this SQL Query that is not comparing properly so I commented it

  • 0

I have this SQL Query that is not comparing properly so I commented it out the WHERE clause. When returning the AF.ActivityNote it always has 2 spaces after it no matter if I do RTRIM on it or not. I think those spaces are the issue that wont let the commented WHERE clause to properly match the string against userfield33.

  SELECT CAST(UF.UserField33 AS NVARCHAR) , RTRIM(CAST(AF.ActivityNote AS NVARCHAR))
        FROM [BCMTEST01].[dbo].[ActivityContacts] as AC INNER JOIN [BCMTEST01].[dbo].[ActivityFullView] as AF
            ON AC.ActivityID = AF.ActivityID INNER JOIN [BCMTEST01].[dbo].[OpportunityExportView] as OP
            ON AC.ContactID = OP.ContactServiceID INNER JOIN [BCMTEST01].[dbo].[UserFields] as UF
            ON OP.ContactServiceID = UF.ContactServiceID
            WHERE ContactID = 8376
        --WHERE  RTRIM(CAST(UF.UserField33 AS NVARCHAR) = RTRIM(CAST(AF.ActivityNote AS NVARCHAR))
        ORDER BY ContactID ASC
  • 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-18T07:10:06+00:00Added an answer on June 18, 2026 at 7:10 am

    First, you should always include the length when converting to nvarchar, varchar, char, and nchar. So use something like:

    cast(uf.userfield33 as nvarchar(255)) -- or whatever length you like, so long as you have something
    

    The last two characters are not spaces. Do something like:

    select ascii(right( AF.ActivityNote, 1))
    

    To see what the character value is. You can then use replace to get rid of it. Or, you can just chop off the last two characters (if that works for your application).

    By the way, I am assuming you are using SQL Server based on the syntax of the query.

    Here is an alternative where clause:

    where (case when right(AF.ActivityNote, 2) = char(10)+CHar(13)
                then LEFT(AF.ActivityNote, LEN(AF.ActivityNote) - 2)
                else AF.ActivityNote
           end) = CAST(UF.UserField33 AS NVARCHAR(255)
    

    I’m not a big fan of case statements in where clauses. I would actually put the logic in a subquery. Also, I might have the order of the 10/13 backwards.

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

Sidebar

Related Questions

Right now I have this SQL query which is valid but always times out:
I have this SQL Query that pulls data from 3 tables. I am unable
I have a custom SQL query that I run with this line: @avg_score =
I have a SQL query in my ASP.net web app that looks like this:
I have this SQL query that I'm writing using Postgresql . select * from
I have this sql query. Wherein I do not want to select the records
I have this Monster SQl Query that looks to fetch data from a Staging
I have created this table with a sql query that looks like this $result
I have this SQL query that does a GROUP BY to merge together all
In one of my process I have this SQL query that take 10-20% of

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.