Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using CAST with concatonate rerturns NULL

Status
Not open for further replies.

NightZEN

Programmer
Apr 29, 2003
142
US
I am trying to concatonate an nvarchar and integere value like so:

SELECT TOP 100 PERCENT cus_key, cus_dataworks_num, CAST(cus_dataworks_num AS nvarchar(10)) + ' - ' + cus_name AS name
FROM dbo.tbl_customer_detailed
ORDER BY cus_name

But cus_dataworks_num can be NULL. When it is, the whole "name" value returns a NULL. How can I replace just the Null cus_dataworks_num with "####" (or something similar, or with a zero length string)?

Thanks
 
Code:
SELECT     TOP 100 PERCENT cus_key, cus_dataworks_num, [red]IsNull([/red]CAST(cus_dataworks_num AS nvarchar(10))[red], '')[/red] + ' -  ' + cus_name AS name
FROM         dbo.tbl_customer_detailed
ORDER BY cus_name

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
By using ISNULL() or COALESCE().

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top