DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login
SQL
IT Tags

Stored Procedure Help

By: rekha singh | 07 May 2010 4:29 pm

I am creating a stored procedure (basic knowledge of sps on my part) and when I try to execute this sp I get an error message. I'm not sure what is wrong with it and how to fix it. Any idea's anyone?

 
create PROCEDURE [dbo].[amhs_ pap_merc_ dx]
As
BEGIN
DECLARE
@Criteria VARCHAR(10)
If patient_diagnosis. icd9cm_code_ id = '272.0'
Set @Criteria = 'True'
Else
Set @Criteria = 'False'
End
 
select * from patient_diagnosis
 
Msg 4104, Level 16, State 1, Procedure amhs_pap_merc_ dx, Line 6
The multi-part identifier "patient_diagnosis_ .icd9cm_code_ id" could not be bound.
 

Comments

The error message should prompt you.
'patient_diagnosis. icd9cm_code_ id' cannot be evaluated. Where is it coming from?
What is the proc trying to do?

 

By: rekha singh | 07 May 2010
You could do something like this:
 
CREATE PROCEDURE [dbo].[amhs_ pap_merc_ dx]
AS
BEGIN
 
DECLARE @Criteria VARCHAR(10)
 
SELECT
Column1,
Column2,
etc
@Criteria = CASE
WHEN ICD9CM_Code_ Id = '272.0' THEN 'True'
ELSE 'False'
END
FROM Patient_Diagnosis
 
END
GO
 
However, its not clear what you are trying to accomplish by setting the @Criteria variable. If there are mulitple rows in the resultset, you may get unpredictable results.
 
Regards,
 

 

By: rekha singh | 07 May 2010
CREATE PROCEDURE [dbo].[amhs_pap_merc_dx]
AS
BEGIN
 
DECLARE @Criteria VARCHAR(10)
 
SELECT @Criteria = ICD9CM_Code_Id FROM Patient_Diagnosis
If @Criteria= '272.0' THEN 'True'
ELSE 'False'
END
 
END
GO
 

Thanks 

By: rekha singh | 07 May 2010
Correction!! !!!!!!!!! !!!!1
 
CREATE PROCEDURE [dbo].[amhs_ pap_merc_ dx]
AS
BEGIN
 
DECLARE @Criteria VARCHAR(10)
 
SELECT @Criteria = Cast(ICD9CM_ Code_Id as Varchar(10)) FROM Patient_Diagnosis
If @Criteria= '272.0' THEN
 
Select 'True'
ELSE
 
Select 'False'
END
 
END
GO
 

Thanks 

By: rekha singh | 07 May 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move