Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-04-05 : 16:02:41
|
HiI have this below CASE Statement which is not returning the value I'm expecting when there is no data.SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[SHOWASSIGN](@RQID int)ASSelect distinct ReqNo = CASEWhen reqno is Null then 'N'When reqno != 0 then 'Y'ENDFROM Customer_AttachmentsWHERE (reqno = @RQID) I want 'N' to return when there is no data for a reqno in the customer_attachments table.I get it right when there is data but it returns nothing when there is no data for a requestWhat am i doing wrong?Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-05 : 16:15:02
|
if you're looking for presence of records make it likeSelect ReqNo = CASEWhen Cnt = 0 then 'N'else 'Y'ENDFROM (SELECT COUNT(*) AS Cnt FROM Customer_AttachmentsWHERE (reqno = @RQID))t ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-04-06 : 08:27:35
|
Thank Youquote: Originally posted by visakh16 if you're looking for presence of records make it likeSelect ReqNo = CASEWhen Cnt = 0 then 'N'else 'Y'ENDFROM (SELECT COUNT(*) AS Cnt FROM Customer_AttachmentsWHERE (reqno = @RQID))t ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-06 : 09:04:04
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|