sorry whats the problem
if you only have a sequence number of 2 then @v_CustUniqNum_1 will be null
also one of the result columns will always be null on each of the rows...
Main Topics
Browse All Topicsselect @v_CustUniqNum_1 =
case
when lcxr.SequenceNum = 1 then
ct.CustUniqNum
end,
@v_CustUniqNum_2 =
case
when lcxr.SequenceNum = 2 then
ct.CustUniqNum
end
from Cust ct, LeadCustXRef lcxr
where lcxr.LeadUniqNum = @v_LeadUniqNum
and lcxr.SequenceNum in (1, 2)
and ct.CustUniqNum = lcxr.CustUniqNum
I am trying to get ct.CustUniqNum corresponding to lcxr.SequenceNum = 1 or 2. But I am getting NULL for @v_CustUniqNum_1. Pl. someone answer asap.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
OK. I figured out the answer. When there are two rows returned for "lcxr.SequenceNum in (1, 2)" for ex: 444, 555, for CASE 1 (@v_CustUniqNum_1), it takes (444, NULL) and the second value NULL is assigned as a latest assignment. So I get NULL for @v_CustUniqNum_1. Whereas, @v_CustUniqNum_2 gets (NULL,555) in CASE 2. So 555 is assigned correctly. Hence I included a 'SUM' function to both the CASEs to suppress the NULL.
select @v_CustUniqNum_1 = SUM (
case
when lcxr.SequenceNum = 1 then
ct.CustUniqNum
end ),
@v_CustUniqNum_2 = SUM (
case
when lcxr.SequenceNum = 2 then
ct.CustUniqNum
end )
from Cust ct, LeadCustXRef lcxr
where lcxr.LeadUniqNum = @v_LeadUniqNum
and lcxr.SequenceNum in (1, 2)
and ct.CustUniqNum = lcxr.CustUniqNum
Pl. let me know, if anyone knows a better way to do this. Thanks for all your comments.
Why don't you use the ISNULL function around the variable equations like so:
select @v_CustUniqNum_1 =
isnull (case
when lcxr.SequenceNum = 1 then
ct.CustUniqNum
end,0),
@v_CustUniqNum_2 =
isnull(case
when lcxr.SequenceNum = 2 then
ct.CustUniqNum
end,0)
from Cust ct, LeadCustXRef lcxr
where lcxr.LeadUniqNum = @v_LeadUniqNum
and lcxr.SequenceNum in (1, 2)
and ct.CustUniqNum = lcxr.CustUniqNum
Otherwise, you could use the ELSE feature:
select @v_CustUniqNum_1 =
case
when lcxr.SequenceNum = 1 then
ct.CustUniqNum
ELSE 0
end,
@v_CustUniqNum_2 =
case
when lcxr.SequenceNum = 2 then
ct.CustUniqNum
ELSE 0
end
from Cust ct, LeadCustXRef lcxr
where lcxr.LeadUniqNum = @v_LeadUniqNum
and lcxr.SequenceNum in (1, 2)
and ct.CustUniqNum = lcxr.CustUniqNum
Business Accounts
Answer for Membership
by: AchetonPosted on 2003-06-26 at 09:33:40ID: 8806639
The SQL looks ok, I would guess that the where clause produces no rows which match, hence the null result.