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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:20:36+00:00 2026-06-12T10:20:36+00:00

Alright let me explain my question with example We have a table that contains

  • 0

Alright let me explain my question with example

We have a table that contains

Id
Name
Number

Now example

1 House 4
2 Hospital 3
3 Airport 'null'
4 Station 2

 select t1.id, 
       t1.name,
       t2.name as name2
from your_table t1
left join your_table t2 on t1.number = t2.id

Ok when querying as the above, that ‘null’ value containing column is giving error. So i want to modify above query in a way that it will return name2 as null and won’t give error for that rows.

So the result I expect should be:

1 House Station
2 Hospital Airport
3 Airport null
4 Station Hospital

This null here is as string.

The current error I get

Msg 245, Level 16, State 1, Line 5
Conversion failed when converting the varchar value ‘null’ to data type smallint.

thank you

  • 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-12T10:20:37+00:00Added an answer on June 12, 2026 at 10:20 am

    You should fix your database design. Meantime, use NULLIF to get your expected results:

    select t1.id, 
           t1.name,
           t2.name as name2
    from your_table t1
    left join your_table t2 on NULLIF( t1.number, 'NULL' ) = t2.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright let me explain my question with example We have 1 table This table
Alright, so let's say I have a database with a table named COMPANY_PARAMETERS that
Alright, let's say I have a table that looks like this: ID | DATE
Alright so I have a task, that I have to let the client try
Alright. Now this question may come to you weird but i have to solve
Alright so let me explain what I'm doing and then I have a couple
Alright, let's say that I have the following markup: <div class=ticker> <p>News Item One.
[Note : I've simplified my example for clarity] Let's say that I have a
Alright let me explain my situation first: I am part of an organization that
Alright, let me start with an example. I have a bunch of items and

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.