Hi
I have below select statement
select salesno,'0' , '0',saleamount from sales
i want 0 to display Blank Space.
Thanks
Hi
I have below select statement
select salesno,'0' , '0',saleamount from sales
i want 0 to display Blank Space.
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jayraj ChhayaPosted Jan 16, 2024, 7:42 AM
To display a blank space instead of the value 0 in a SQL select statement, you can use the
CASEstatement. Here's an example:Amit MohantyPosted Jan 16, 2024, 6:18 AM
Hey Ramco, can you provide your full query along with union?
Naimish MakwanaPosted Jan 16, 2024, 6:09 AM
The error you’re seeing is because SQL Server is trying to convert an empty string
''to a numeric data type, which is not possible. When you useUNION, SQL Server requires that the data types of the corresponding columns in theSELECTstatements match.If you want to replace
'0'with a blank space in a numeric column when usingUNION, you’ll need to convert all the numeric columns toVARCHARorNVARCHAR. Here’s an example:In this query, replace
column1andcolumn2with the actual column names where you want to replace'0'with a blank space. This query will check each row ofcolumn1andcolumn2, and if the value is'0', it will replace it with an empty string''; otherwise, it will keep the original value.Please note that this will convert your numeric columns to string columns, which might affect any subsequent numeric operations you want to perform on these columns. If you need to perform numeric operations on these columns after the
UNION, you might need to convert them back to a numeric data type.Thanks
Ramco RamcoPosted Jan 16, 2024, 5:56 AM
Hi naimish
Below is the hardcoed query . I have used union. When i write '' in place of 0 then it gives error "Error converting datatype varchar to numeric.
Thanks
Muhammad Imran AnsariPosted Jan 16, 2024, 5:25 AM
Your question is not cleared. If you want to show empty/black space instead of '0' then you can use CASE statement like below otherwise improve your question.
Naimish MakwanaPosted Jan 16, 2024, 5:22 AM
Please use below query.
Thanks