chicho12
asked on
SQL - Comparing the value returned by a Select against a Parameter in a Store Procedure
Hi
IN the Store Procedure below Im trying to compare the value returned by the Select statement against the parameter @SalesRepFullName. I am always getting a 'NotMatch' even when the value of the parameter passed is the same as what the Select should be returning. Can someone let me know what am I missing? THanks
ALTER procedure [LFO].[testSP]
@SalesRepFullName varchar(100),
@ContractNr nvarchar(50),
@StatusFlag varchar(4000) OUT
AS
BEGIN
BEGIN TRY
DECLARE @FullName varchar(100);
SELECT @FullName = LTRIM(RTRIM([dbo].Account. SalesRepFu llName))
FROM [dbo].Account
WHERE [dbo].Account.ContractNr = @ContractNr
IF @FullName = LTRIM(RTRIM(@SalesRepFullN ame))
select @StatusFlag = 'Match'
ELSE
select @StatusFlag = 'NotMatch'
END TRY
BEGIN CATCH
select @StatusFlag = ERROR_MESSAGE()
END CATCH
END
IN the Store Procedure below Im trying to compare the value returned by the Select statement against the parameter @SalesRepFullName. I am always getting a 'NotMatch' even when the value of the parameter passed is the same as what the Select should be returning. Can someone let me know what am I missing? THanks
ALTER procedure [LFO].[testSP]
@SalesRepFullName varchar(100),
@ContractNr nvarchar(50),
@StatusFlag varchar(4000) OUT
AS
BEGIN
BEGIN TRY
DECLARE @FullName varchar(100);
SELECT @FullName = LTRIM(RTRIM([dbo].Account.
FROM [dbo].Account
WHERE [dbo].Account.ContractNr = @ContractNr
IF @FullName = LTRIM(RTRIM(@SalesRepFullN
select @StatusFlag = 'Match'
ELSE
select @StatusFlag = 'NotMatch'
END TRY
BEGIN CATCH
select @StatusFlag = ERROR_MESSAGE()
END CATCH
END
ASKER
yes, it returned values.
i just added this line below in the ELSE section and its updating the expected row. So its finding the record but some how the comparison of values is never returning true.
I am testing the Stored pROcedure in SQL server management.
Update [dbo].Account set SalesRepFullName =LTRIM(RTRIM(@SalesRepFull Name)) ,UpdatedOn = getdate() where ContractNr = @ContractNr
i just added this line below in the ELSE section and its updating the expected row. So its finding the record but some how the comparison of values is never returning true.
I am testing the Stored pROcedure in SQL server management.
Update [dbo].Account set SalesRepFullName =LTRIM(RTRIM(@SalesRepFull
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You were right the contract had a character a the end that didnt see before. THanks for the help!!
Open in new window