473,406 Members | 2,549 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,406 software developers and data experts.

Need help returning a null value, please

I've got the following query in SQL 2000:

select a.SSN, a.MonthName, a.IMClinicDay,
b.IMClinicDay as SecondDay
from tblResidentRotations a
inner join view7 b
on a.SSN = b.SSN
where a.AcademicYear = '2004-2005' and a.SSN = '999999999' and
datename(month, a.IMClinicDateFirst) = b.MonthName

This query returns a resultset like this:

<SSN> <Month> <a.IMClinicDay> <SecondDay>
999999999 July Friday PM Tuesday PM
999999999 September Tuesday PM Friday PM
999999999 October None Friday PM
999999999 November Friday PM Tuesday PM
999999999 January Tuesday PM Friday PM
999999999 April Friday PM Monday PM
....and so on
For some of the months, there is a null value for "b.IMClinicDay". For
example, it's null for August, December, and February. I want my
resultset to look like this:

<SSN> <Month> <a.IMClinicDay> <SecondDay>
999999999 July Friday PM Tuesday PM
999999999 August Tuesday PM null
999999999 September Tuesday PM Friday PM
999999999 October None Friday PM
999999999 November Friday PM Tuesday PM
999999999 December Tuesday PM null
999999999 January Tuesday PM Friday PM
999999999 February Friday PM null
999999999 April Friday PM Monday PM
....and so on
How can I return a null for these days? Thanks for any help or
advice.

Jul 23 '05 #1
4 1271
Stu
Use a LEFT JOIN instead of an INNER JOIN.

SELECT a.SSN, a.MonthName, a.IMClinicDay,
b.IMClinicDay as SecondDay
FROM tblResidentRotations a LEFT JOIN view7 b ON a.SSN = b.SSN
WHERE a.AcademicYear = '2004-2005'
AND a.SSN = '999999999'
AND datename(month, a.IMClinicDateFirst) = b.MonthName

HTH
Stu

Jul 23 '05 #2
On 31 May 2005 12:15:27 -0700, Stu wrote:
Use a LEFT JOIN instead of an INNER JOIN.

SELECT a.SSN, a.MonthName, a.IMClinicDay,
b.IMClinicDay as SecondDay
FROM tblResidentRotations a LEFT JOIN view7 b ON a.SSN = b.SSN
WHERE a.AcademicYear = '2004-2005'
AND a.SSN = '999999999'
AND datename(month, a.IMClinicDateFirst) = b.MonthName

HTH
Stu


Hi Stu,

One correction. The last line of the WHERE clause has to move to the ON
clause:

SELECT a.SSN, a.MonthName, a.IMClinicDay,
b.IMClinicDay as SecondDay
FROM tblResidentRotations a
LEFT JOIN view7 b
ON a.SSN = b.SSN
AND datename(month, a.IMClinicDateFirst) = b.MonthName
WHERE a.AcademicYear = '2004-2005'
AND a.SSN = '999999999'

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3
Thanks Stu and Hugo. I got the resultset I wanted.

Hugo Kornelis wrote:
On 31 May 2005 12:15:27 -0700, Stu wrote:
Use a LEFT JOIN instead of an INNER JOIN.

SELECT a.SSN, a.MonthName, a.IMClinicDay,
b.IMClinicDay as SecondDay
FROM tblResidentRotations a LEFT JOIN view7 b ON a.SSN = b.SSN
WHERE a.AcademicYear = '2004-2005'
AND a.SSN = '999999999'
AND datename(month, a.IMClinicDateFirst) = b.MonthName

HTH
Stu


Hi Stu,

One correction. The last line of the WHERE clause has to move to the ON
clause:

SELECT a.SSN, a.MonthName, a.IMClinicDay,
b.IMClinicDay as SecondDay
FROM tblResidentRotations a
LEFT JOIN view7 b
ON a.SSN = b.SSN
AND datename(month, a.IMClinicDateFirst) = b.MonthName
WHERE a.AcademicYear = '2004-2005'
AND a.SSN = '999999999'

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Jul 23 '05 #4
Stu
Ahhh, I suck at multitasking. Shows what happens when you cut and
paste without looking too closely :)

Jul 23 '05 #5

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
12
by: LongBow | last post by:
Hello all, From doing a google serach in the newsgroups I found out that a string can't be returned from a function, but using a char* I should be able to do it. I have spent most of the day...
1
by: john | last post by:
Relatively new to C coding, so any help would greatly be appreciated. I'm having problems try to return my string array from my parsing function. When I do a printf I am getting the correct value...
9
by: Thomas Mlynarczyk | last post by:
Hi, It seems to be a generally adopted convention to have a function return FALSE in case of an error. But if a function is supposed to return a boolean anyway, one cannot distinguish anymore...
6
by: Josh Close | last post by:
I'm having a problem with a value coming out of a loop. CREATE OR REPLACE FUNCTION funmessagespermintotal() RETURNS int8 AS ' DECLARE this_rServer record; this_rSum record; this_iSum...
7
by: ÀÏÆÅ»³ÔÐ5¸öÔ | last post by:
I want use dropdownlist contral in gridview but have trouble now mycode here: i'm very sorry for my poor english <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"...
1
by: anonymous.user0 | last post by:
Whats the common/best practice for returning a "Does not exist/not found" result from a function. Imagine I've got a function: myObjectType GetById(long id); where the object may or may not...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
3
by: bogdan | last post by:
Hi, I have a stored procedure that returns a single value. Example: SELECT @RowCount = COUNT(*) FROM t WHERE RETURN @RowCount I created a data set, table adapter, and adapter's method...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.