|
Home > Archive > MS SQL Server > November 2005 > Null valus in a select
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Null valus in a select
|
|
|
| How do I check of null in a select clause and replace them with space/empty
string?
| |
| David Portas 2005-11-29, 11:23 am |
| SELECT COALESCE(col_x, '') AS col_x
FROM your_table ;
--
David Portas
SQL Server MVP
--
| |
| Robert Klemme 2005-11-29, 11:23 am |
| David Portas wrote:
> SELECT COALESCE(col_x, '') AS col_x
> FROM your_table ;
or
SELECT ISNULL(col_x, '') AS col_x
FROM your_table
robert
| |
|
| That kind of works, except if the column is a smallint I get 0 instead of ''
"David Portas" wrote:
> SELECT COALESCE(col_x, '') AS col_x
> FROM your_table ;
>
> --
> David Portas
> SQL Server MVP
> --
>
>
| |
|
| That kind of works, except if the column is a smallint I get 0 instead of ''
"Robert Klemme" wrote:
> David Portas wrote:
>
> or
>
> SELECT ISNULL(col_x, '') AS col_x
> FROM your_table
>
> robert
>
>
| |
| Gert-Jan Strik 2005-11-29, 8:23 pm |
| Arne,
An expression in the Selection List can only return the predefined data
type. If you want to return a smallint, then by definition, you cannot
return an empty string. If returning a string works for you, then you
can use this:
SELECT COALESCE(CAST(col_x AS VARCHAR(11)), '') AS col_x
FROM your_table
Gert-Jan
Arne wrote:[color=darkred
]
>
> That kind of works, except if the column is a smallint I get 0 instead of ''
>
> "Robert Klemme" wrote:
>
| |
|
| Try this.
SELECT ISNULL(CONVERT(VARCH
AR(5),col_x), '') AS col_x FROM your_table
"Arne" wrote:
[color=darkred]
> That kind of works, except if the column is a smallint I get 0 instead of ''
>
>
>
> "Robert Klemme" wrote:
>
|
|
|
|
|