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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:45:32+00:00 2026-06-09T12:45:32+00:00

Today I was testing something at work place and came across this one Case

  • 0

Today I was testing something at work place and came across this one

Case 1:

Declare @a nvarchar(20)
Set @a = null
Select IsNull(LTrim(RTrim(Lower(@a))), -1)

Case 2:

Select IsNull(LTrim(RTrim(Lower(null))), -1)

The result in case 1 is -1 but * in case 2
I was expecting same results in both cases. Any reason?

  • 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-09T12:45:34+00:00Added an answer on June 9, 2026 at 12:45 pm

    Without the declaration of data type, null in this case is declared as varchar(1). You can observe this by selecting the results into a #temp table:

    Select IsNull(LTrim(RTrim(Lower(null))), -1) as x INTO #x;
    EXEC tempdb..sp_help '#x';
    

    Among the results you’ll see:

    Column_name   Type      Length
    -----------   -------   ------
    x             varchar   1
    

    Since -1 can’t fit in a varchar(1), you are getting * as output. This is similar to:

    SELECT CONVERT(VARCHAR(1), -1);
    

    If you want to collapse to a string, then I suggest enclosing the integer in single quotes so there is no confusion caused by integer <-> string conversions that aren’t intended:

    SELECT CONVERT(VARCHAR(1), '-1'); -- yields "-"
    SELECT CONVERT(VARCHAR(30), '-1'); -- yields "-1"
    

    I would not make any assumptions about how SQL Server will handle a “value” explicitly provided as null, especially when complex expressions make it difficult to predict which evaluation rules might trump data type precedence.

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

Sidebar

Related Questions

I ran into this situation today. I have an object which I'm testing for
I thought I knew everything about encodings and Python, but today I came across
Today I tried to cache re.compile to speed up my testing. Something got weird:
I was testing a file management program today and while looking to solve something
Today in the morning I was testing my code suddenly I got this error.
Today, for the first time, I came across the YUI 2 Rich Text Editor
I ran into this today when unit testing a generic dictionary. System.Collections.Generic.Dictionary<int, string> actual,
(Not to be confused with Xunit , a popular .Net unit testing library.) Today
I'm testing a few NoSQL solution and I'm focusing mainly on read performance. Today
Today at work, I was given a task to fix a bug within our

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.