You are viewing limited content. For full access, please sign in.

Question

Question

retrieve data from stored procedure with if clause

asked on February 8, 2024 • Show version history

Hi.

I'm using a SP to return a value for LookUp Rules

My SP in quite simple:

If the first select return a value, exec a select on table 1, else, exec select on table 2.

The problem is: Laserfiche doesn't recognize the variable returned on the IF CLAUSE (select Table 1 or 2 (UserName)), just UserNameTemp.


ALTER   PROCEDURE [dbo].[sp123] 
(
@Number VARCHAR(20),	
@Code VARCHAR(100)

)
AS
BEGIN
SET NOCOUNT ON;

DECLARE @UserName VARCHAR(300);

	SELECT TOP 1
	UserName AS UserNameTemp --this variable works
	FROM
	MyTable0
	WHERE
	Number = @Number

if @@ROWCOUNT	 = 1

	BEGIN
		SELECT TOP 1
		UserName -- LF doesn't read this variable
		FROM
		MyTable1
		WHERE
		Number = @Number

	END
ELSE
	BEGIN
		SELECT TOP 1
		UserName -- LF doesn't read this variable
		FROM
		MyTable2
		WHERE
		Number = @Number

	END


END;

 

0 0

Replies

replied on March 12, 2024

Cris,

 Have you tried adding "AS UserNameTemp" after UserName for all SELECT statements?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.