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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

default value in select 2

Status
Not open for further replies.

icemel

MIS
Oct 17, 2005
463
US
Hi,

What is the best way to write this?

In a SELECT statement, if the value selected is null, then use a default value instead. Is a case statment the way to go?

Thanks
 
Select IsNull(FieldName, 'HardCodedDate')

Or you could use Coalesce:

Select Coalesce(FieldName, 'HardCodedDate')


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi, thanks. Not sure what I'm doing wrong here...

ALTER VIEW [dbo].[MailList]
AS
SELECT DISTINCT C.Email, C.Name, IsNull(c.webAddr, 'FROM dbo.Contacts AS C LEFT OUTER JOIN

Error:

Create View or Function failed because no column name was specified for column 3.

THANKS
 
You're missing an apostrophe and you must give the column an alias

Code:
ALTER   VIEW [dbo].[MailList]
AS
SELECT DISTINCT C.Email, C.Name, IsNull(c.webAddr, 'www.defaultwebsite.com[!]'[/!]) [!]As SomeColumnName[/!]
FROM dbo.Contacts AS C LEFT OUTER JOIN

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top