Avatar of HADDADD3
HADDADD3
 asked on

Stored Procedure Returning Wrong Result

See the SP below.

The table column has the value

"b3148336-3c1b-44ed-a059-14dbb3.tif" stored in it. The stored procedure should return that value.

The stored procedure is actually returning "b3148336-3c1b-44ed-a059-14dbb3"

Why is it trunkating the .tif from the return value? It is cast in the DB as a varchar(40)

What else should i check/test? If i just run the query in query analyzer it works fine
select image_file from patient_images where person_ID=(pid)

that returns the correct result. Im wondering if its a cast issue, any thoughts?
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
 
 
 
ALTER       Procedure lei_get_last_test_image
    (
        @pid varchar(50),
	@imagetype varchar(50),
	@imagename nvarchar(40) OUTPUT
 
)
As
select @imagename=image_file
 
 
from patient_images
 
 
where person_id=@pid
AND image_desc LIKE @imagetype
 
 
 
 
 
 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

Open in new window

Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
jaryco

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
UnifiedIS

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RDWaibel

I would change the nvarchar(40  to Varchar(40) for starters

SOLUTION
THBA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jaryco

Just a trivial question, the field image_file has the full image name with the extension? Or could be another field with that information.

As THBA said, what happens if you executes for example:
SELECT * -- try with * to see if there are a different field with that information
FROM patient_images
WHERE person_id=  *** put the id here
AND image_desc LIKE *** put the desc here

Is the "image_file" information complete or there are any other field?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck