Help Me in writting a stored procedure ...I have written most of it using normal programming syntaxes

Can you please hellp me in writting this stored procedure in correct format...I have no knowledge of SP but I worte this as we write using programming language with comments
Below I am pasting two stored procedures please ask me if you are not clear
1 procedure is SP_DATAEVAL which calls 2nd Procedure SP_DATAEVAL2 after set of steps

1)
CREATE PROCEDURE dbo.SP_DATAEVAL
/*below are three inputs for my SP*/
      @carrierid as int,
      @pulseresitor as double,
      @onboardres as double      
AS

if(SELECT PARAMETERVALUE FROM TBLPARAMETER WHERE (STEPID IN(SELECT STEPID FROM TBLSTEP WHERE (RECIPEID IN(SELECT DISTINCT TOP 1 RECIPEID FROM TBLCARRIERRECIPE WHERE CARRIERID IN(SELECT CARRIERID FROM TBLCARRIER WHERE CARRIERNUMBER = @carrierid) AND CARRIERRECIPEISACTIVE = 'True' )AND STEPORDER=1 AND STEPTYPE=1))AND PARAMETERTYPE =1)) in(2,3)
{
     If(@plugresistor =0)
     {
    Print :"Error"
    }
    Else
    declare @paravalue as varchar(10)
    set @paravalue = (SELECT PARAMETERVALUE FROM TBLPARAMETER WHERE (STEPID IN                  (SELECT STEPID FROM TBLSTEP WHERE (RECIPEID IN(SELECT DISTINCT TOP 1 RECIPEID FROM                 TBLCARRIERRECIPE WHERE CARRIERID IN(SELECT CARRIERID FROM TBLCARRIER WHERE CARRIERNUMBER = @carrierid) AND CARRIERRECIPEISACTIVE = 'True' )AND STEPORDER=1 AND STEPTYPE=1))AND PARAMETERTYPE =2))
     If @paravalue >= @plugresistor * 0.98 And @paravalue <= @paravalue * 1.02
      {
/* should call a sub procedure
Me assume it as EXEC SP_DATAEVAL2 */
EXEC DATAVAL2 @carrierid
      }
Else

Print:"Error"
      /* SET NOCOUNT ON */
      RETURN
}
Else
{
 EXEC DATAEVAL2 @carrierid
}
......................................................................................
2) SP_DATAEVAL2(Note this procedure is working fine)

ALTER PROCEDURE dbo.SP_DATAEVAL2
      @Carrierid as int,
      @abc as int
      
AS
declare @recipetype as int

set @recipetype = (SELECT DISTINCT RECIPETYPE FROM TBLRECIPE WHERE (RECIPEID IN(SELECT RECIPEID FROM TBLCARRIERRECIPE WHERE CARRIERID IN(SELECT CARRIERID FROM TBLCARRIER WHERE CARRIERNUMBER = @carrierid)AND CARRIERRECIPEISACTIVE = 'TRUE')))

      /* SET NOCOUNT ON */
      RETURN @recipetype
AnushartAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
CREATE PROCEDURE dbo.SP_DATAEVAL
/*below are three inputs for my SP*/
      @carrierid as int,
      @plugresistor as bigint,
      @onboardres as bigint      
AS

if(SELECT PARAMETERVALUE FROM TBLPARAMETER WHERE (STEPID IN(SELECT STEPID FROM TBLSTEP WHERE (RECIPEID IN(SELECT DISTINCT TOP 1 RECIPEID FROM TBLCARRIERRECIPE WHERE CARRIERID IN(SELECT CARRIERID FROM TBLCARRIER WHERE CARRIERNUMBER = @carrierid) AND CARRIERRECIPEISACTIVE = 'True' )AND STEPORDER=1 AND STEPTYPE=1))AND PARAMETERTYPE =1)) in(2,3)
BEGIN
     If(@plugresistor =0)
     BEGIN
    return (-201)
    end
    Else
    declare @paravalue as varchar(10)
    set @paravalue = (SELECT PARAMETERVALUE FROM TBLPARAMETER WHERE (STEPID IN                  (SELECT STEPID FROM TBLSTEP WHERE (RECIPEID IN(SELECT DISTINCT TOP 1 RECIPEID FROM                 TBLCARRIERRECIPE WHERE CARRIERID IN(SELECT CARRIERID FROM TBLCARRIER WHERE CARRIERNUMBER = @carrierid) AND CARRIERRECIPEISACTIVE = 'True' )AND STEPORDER=1 AND STEPTYPE=1))AND PARAMETERTYPE =2))
     If @paravalue >= @plugresistor * 0.98 And @paravalue <= @paravalue * 1.02
      BEGIN
/* should call a sub procedure
Me assume it as EXEC SP_DATAEVAL2 */
EXEC DATAVAL2 @carrierid
      end
Else

return (-201)
end
Else
BEGIN
 EXEC DATAEVAL2 @carrierid
end
0
 
AnushartAuthor Commented:
Thanks anneshattingal ...It worked !!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.