473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Select CASE returning NULL value

I have the following CASE statement in a view:

(SELECT CASE
WHEN ISNULL([dbo].[tblContact].[JobTitleID], NULL) = NULL
THEN [dbo].[f_ContactNameFL]([dbo].[tblContact].[ContactID])
ELSE [dbo].[f_ContactNameFL]([dbo].[tblContact].[ContactID]) + ', ' +
[dbo].[tlkpJobTitle].[Title]
END) AS ContactNameAndTitle

It works perfectly when dbo.tblContact.JobTitleID is NOT null. When it
is null it should return a contact name but it is returning null. The
problem is not f_ContactNameFL. There is another column in the same
view that uses that function and it works perfectly. What am I doing
wrong?

Thanks,
Shelley
Jun 27 '08 #1
1 7451
You cannot check NULL for equality (it is unknown, so it doesn't equal
another unknown). The correct way to check if expression is NULL is using IS
NULL:

CASE WHEN [dbo].[tblContact].[JobTitleID] IS NULL THEN ...

The code that you posted can be simplified using the COALESCE function:

[dbo].[f_ContactNameFL]([dbo].[tblContact].[ContactID]) +
COALESCE(', ' + [dbo].[tlkpJobTitle].[Title], '') AS ContactNameAndTitle

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
5
by: Muhd | last post by:
Hey all, I have a basic table that looks something like this. CREATE TABLE MyTable ( ID INT IDENTITY PRIMARY KEY, Company_ID INT NOT NULL, Round VARCHAR(50) NOT NULL, Details VARCHAR(250)...
7
by: Sunny K | last post by:
Hi guys, whilst working on a project which I thought was nearly complete I have come across a problem which was some how over seen, which I am hoping one of you guys know how to resovle. ...
5
by: Reestit Mutton | last post by:
Hi, I'm currently learning the ropes with CSS, PHP, MYSQL, Javascript etc... by redesigning my website as a database driven site. Okay, so I'm skilled at perl, data manipulation and data...
1
by: gilgantic | last post by:
HELP!!! I am trying to fine tune or rewrite my SELECT statement which has a combination of SUM and CASE statements. The values are accurate, but the query is slow. BUSINESS RULE =============...
5
by: John | last post by:
I just cannot manage to perform a SELECT query with NULL parameter... My CATEGORY table does have one row where TCATEGORYPARENTID is null (real DB null value). TCATEGORYID and TCATEGORYPARENTID...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
4
by: troy_lee | last post by:
I have a form that acts a filter. All of the filtering objects are in the header and the results are displayed in a continuous form in the detail section. In the header, I have a text box...
4
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie in php and I got error in my index.php which is: 1054 - Unknown column 'p.products_id' in 'on clause' select p.products_image, pd.products_name, p.products_id,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.