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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 If Statement

Author  Topic 

stahorse
Yak Posting Veteran

86 Posts

Posted - 2012-09-11 : 07:26:49
Hi

I have this store proc below and it gives me this error when I try to exec it: "Command(s) completed successfully." I am expecting values back, and I get that message instead

PROC
@AppId VARCHAR(10)

--validate input
declare @a varchar(16)
select @a = b.NAME
from S_OPTY a
inner join S_SALES_METHOD b
on a.METHOD_ID = b.ROW_ID
where a.NAME = @AppId

IF @a = 'Top Ups' or @a = 'Top Ups - Retirement'

BEGIN

SELECT

@AppId AS Application_Id
, MB.POLICY_ID AS Policy_Id
, MH.BFN_CHG_DATE AS Date_Of_Disinvestment


FROM PR_MONEY_BFN MB WITH (NOLOCK)

LEFT JOIN PR_MONEY_HIST MH WITH (NOLOCK)
ON MB.POLICY_ID = MH.POLICY_ID
AND MB.BUS_FUNC_CLASS = MH.BUS_FUNC_CLASS
AND MB.BUS_FUNC_DATE = MH.BUS_FUNC_DATE
AND MB.BUS_FUNC_NUMBER = MH.BUS_FUNC_NUMBER
AND MH.BUS_FUNC_STATUS = '80'

LEFT JOIN S_OPTY SO WITH (NOLOCK)
ON SO.NAME = MB.APPLICATION_NO

WHERE SO.NAME = @AppId

END

--exec prc_TopUpCancellation @AppId = '1-108719398'

please help

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-09-11 : 07:30:46
I suspect the value of @a turns out to be something other than the two that you are expecting. Insert a print statement before the IF (see below) and see what the value is.
.....
DECLARE @a VARCHAR(16)
SELECT @a = b.NAME
FROM S_OPTY a
INNER JOIN S_SALES_METHOD b
ON a.METHOD_ID = b.ROW_ID
WHERE a.NAME = @AppId

PRINT @a;


IF @a = 'Top Ups'
OR @a = 'Top Ups - Retirement'
BEGIN
......
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-11 : 11:21:27
one thing i noticed is you've declared @a as

declare @a varchar(16)
and using check condition as

@a = 'Top Ups - Retirement'

here string is over 16 characters long so if you're expecting similar values alter @a to much higher value to hold them all

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -