Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

How convert NULL to empty string in select statement?

 
   Database Help (Home) -> Programming RSS
Next:  Temp Table and Dynamic SQL  
Author Message
ChrisB1

External


Since: Oct 30, 2003
Posts: 6



(Msg. 1) Posted: Mon Nov 06, 2006 1:39 pm
Post subject: How convert NULL to empty string in select statement?
Archived from groups: microsoft>public>sqlserver>programming (more info?)

Hello:

I was wondering, given the following select statement is there an easy was
to return an empty string for the FirstName field if the value is NULL? I'm
not quite sure of the necessary syntax:

// If FirstName IS NULL, FirstName should = ''
SELECT FirstName, Age, State FROM Customers WHERE CustomerID = @CustomerID

Thanks,
Chris

 >> Stay informed about: How convert NULL to empty string in select statement? 
Back to top
Login to vote
Barry

External


Since: Jul 07, 2006
Posts: 9



(Msg. 2) Posted: Mon Nov 06, 2006 1:39 pm
Post subject: Re: How convert NULL to empty string in select statement? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Select IsNull(Firstname, '') As 'Firstname', Age, State From Customers
Where CustomerID = @CustomerID

HTH

Barry



ChrisB wrote:
> Hello:
>
> I was wondering, given the following select statement is there an easy was
> to return an empty string for the FirstName field if the value is NULL? I'm
> not quite sure of the necessary syntax:
>
> // If FirstName IS NULL, FirstName should = ''
> SELECT FirstName, Age, State FROM Customers WHERE CustomerID = @CustomerID
>
> Thanks,
> Chris

 >> Stay informed about: How convert NULL to empty string in select statement? 
Back to top
Login to vote
Tracy McKibben

External


Since: Nov 21, 2006
Posts: 285



(Msg. 3) Posted: Mon Nov 06, 2006 1:39 pm
Post subject: Re: How convert NULL to empty string in select statement? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

ChrisB wrote:
> Hello:
>
> I was wondering, given the following select statement is there an easy was
> to return an empty string for the FirstName field if the value is NULL? I'm
> not quite sure of the necessary syntax:
>
> // If FirstName IS NULL, FirstName should = ''
> SELECT FirstName, Age, State FROM Customers WHERE CustomerID = @CustomerID
>
> Thanks,
> Chris
>
>
>

SELECT
COALESCE(FirstName, '') AS FirstName,
Age,
State
FROM Customers
WHERE CustomerID = @CustomerID



--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
 >> Stay informed about: How convert NULL to empty string in select statement? 
Back to top
Login to vote
ChrisB1

External


Since: Oct 30, 2003
Posts: 6



(Msg. 4) Posted: Mon Nov 06, 2006 2:00 pm
Post subject: Re: How convert NULL to empty string in select statement? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks, Barry.

"Barry" wrote in message

>
> Select IsNull(Firstname, '') As 'Firstname', Age, State From Customers
> Where CustomerID = @CustomerID
>
> HTH
>
> Barry
>
>
>
> ChrisB wrote:
>> Hello:
>>
>> I was wondering, given the following select statement is there an easy
>> was
>> to return an empty string for the FirstName field if the value is NULL?
>> I'm
>> not quite sure of the necessary syntax:
>>
>> // If FirstName IS NULL, FirstName should = ''
>> SELECT FirstName, Age, State FROM Customers WHERE CustomerID =
>> @CustomerID
>>
>> Thanks,
>> Chris
>
 >> Stay informed about: How convert NULL to empty string in select statement? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to convert rows to columns in Select statement - Hello All, I have a table that contains period and value. eg. Period Value 1 33 2 67 3 11 4 10 5 21 6 44 7 34 I want to convert to these rows to columns like following 1 2 3 ...

testing for null and not null in case statement - I want to know whether a field has a date or not, and then group by that result in a query. I'm trying: case activate_date when null then 'active next bill date' when not null then 'active' end and it didn't like that. Didn't like that "not&quot...

Elegant empty string equivalent to isnull( ) ??? - Hi All. In the past all my tables have allowed null values on almost everything. For the first time, I'm working on a DB that does not allow null values. I'm so used to the ISNULL and COALESCE functions when performing simple concatenations, I don't..

bcp out empty string into csv file - I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp tool, empty string gets written as NUL characte...

Function to convert Null values to a specified value - Is ther a function is SQL Server to convert Null values to "0" or some other specified value, similar to MS-Access?
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]