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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:14:34+00:00 2026-06-09T09:14:34+00:00

I am using SQL Server 2005. I am trying to do a select from

  • 0

I am using SQL Server 2005. I am trying to do a select from a TINYINT field. If the field’s value is 0 I want to select an empty string instead ‘ ‘ . The fields name is level. HEre is what I am doing:

SELECT 
[Level] = 
Case 
t.[Level]
    WHEN 0 THEN ' '
    ELSE t.[Level]
END
FROM table t 

This code always returns 0. I was trying to troubleshoot the issue and tried this:

SELECT 
[Level] = 
Case 
t.[Level]
    WHEN 0 THEN 'test'
    ELSE t.[Level]
END
FROM table t 

And I got a the error Conversion failed when converting the varchar value 'test' to data type tinyint

So I’m seeing that there is a conversion problem here. I’ve tried:

SELECT 
[Level] = 
Case 
t.[Level]
    WHEN 0 THEN CONVERT(VARCHAR,t.[level])
    ELSE t.[Level]
END
FROM table t 

But this of course still returns 0, just the character, so it’s still not doing what I need. I am thinking that there is most likely a better way to do this but am not sure how to approach it. Could anyone give me some advice on how to handle this? Thanks much!

  • 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-09T09:14:35+00:00Added an answer on June 9, 2026 at 9:14 am

    For CASE statements, all returned values must be of the same type (or automatically convertable); that’s the reason why '' was working, but 'test' wasn´t.

    SELECT [Level] = 
    Case t.[Level]
        WHEN 0 THEN ' '
        ELSE CONVERT(VARCHAR(3), t.[Level])
    END
    FROM table t 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2005 I want to filter the column where column value not
Using SQL Server 2005, I am trying to select a certain number of records
I am using SQL Server 2005. I am trying to SELECT a list of
I'm using SQL Server 2005 Analysis Services and I'm trying to calculate distance inside
I am trying to learn SQL query optimization using SQL Server 2005. However, I
I am trying to insert certain values into the table using SQL server 2005.
I'm trying to configure replication on SQL Server 2005. I can do it using
I am using SQL Server 2008 & 2005 (Express). I'm trying to extract part
Using SQL Server 2005 I have a query that gets child records from bundles
[using SQL Server 2005] I have a table full of users, I want 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.