Stored Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweatha
    New Member
    • Mar 2008
    • 44

    Stored Procedure

    Hi

    I have to convert the following query into stored procedure

    "select DoctorMaster.Fi rstName+''+Doct orMaster.Middle Name+''+DoctorM aster.LastName as DoctorsName,Doc torMaster.DRID, DoctorMaster.Ge nder,DrClinicDe tails.Address,D octorMaster.Tel ephone+','+Doct orMaster.Mobile as Phone,PrimaryTi tle.PrimaryTitl e from DoctorMaster,Dr ClinicDetails,P rimaryTitle,Spe cialty where DoctorMaster.Fi rstName like '" + obj.ToString() + "%' or Specialty.Speci alty='" + obj1.ToString() + "' or DoctorMaster.Ci ty='" + obj2.ToString() + "' and DoctorMaster.DR ID=DrClinicDeta ils.DRID and DoctorMaster.SP ID=Specialty.SP ID and PrimaryTitle.PT ID=DoctorMaster .PrimaryTitleID "

    For that I have written the stored procedure as

    set ANSI_NULLS ON
    set QUOTED_IDENTIFI ER ON
    go

    -- =============== =============== ===============
    -- Author: <Author,,Name >
    -- Create date: <Create Date,,>
    -- Description: <Description, ,>
    -- =============== =============== ===============
    CREATE PROCEDURE [dbo].[Pro_Grid]

    @FirstName nvarchar(100)ou tput,
    @MiddleName nvarchar(100)ou tput,
    @LastName nvarchar(100)ou tput,
    @DRID nvarchar(12)out put,
    @Gender bit output,
    @Address nvarchar(255)ou tput,
    @Telephone nvarchar(50)out put,
    @Mobile nvarchar(50)out put,
    @PrimaryTitle nvarchar(20)out put,
    @Specialty nvarchar(50)out put,
    @City nvarchar(100)ou tput
    @SPID nvarchar(12)out put,
    @PTID nvarchar(12)out put,
    @PrimaryTitleID nvarchar(12)out put


    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.


    -- Insert statements for procedure here
    -- select @SPID=SPID,@Spe cialty=Specialt y from Specialty

    select DoctorMaster.Fi rstName+''+Doct orMaster.Middle Name+''+DoctorM aster.LastName as DoctorsName,Doc torMaster.DRID, DoctorMaster.Ge nder,DrClinicDe tails.Address,D octorMaster.Tel ephone+','+Doct orMaster.Mobile as Phone,PrimaryTi tle.PrimaryTitl e from DoctorMaster,Dr ClinicDetails,P rimaryTitle,Spe cialty where DoctorMaster.Fi rstName like DoctorMaster.@F irstName or Specialty.Speci alty=Specialty. @Specialty or DoctorMaster.Ci ty=DoctorMaster .@City and DoctorMaster.DR ID=DrClinicDeta ils.DRID and DoctorMaster.SP ID=Specialty.SP ID and PrimaryTitle.PT ID=DoctorMaster .PrimaryTitleID
    -- insert into Specialty (SPID,Specialty )
    -- values(@SPID,@S pecialty)

    END

    But if I execute, I got the error as

    Msg 102, Level 15, State 1, Procedure Pro_Grid, Line 20
    Incorrect syntax near '@SPID'.
    Msg 102, Level 15, State 1, Procedure Pro_Grid, Line 34
    Incorrect syntax near '@FirstName'.
  • deepuv04
    Recognized Expert New Member
    • Nov 2007
    • 227

    #2
    CREATE PROCEDURE [dbo].[Pro_Grid]

    @FirstName nvarchar(100),
    @Specialty nvarchar(50),
    @City nvarchar(100)


    AS
    BEGIN

    select DoctorMaster.Fi rstName+''+Doct orMaster.Middle Name+ ''+DoctorMaster .LastName as DoctorsName,
    DoctorMaster.DR ID,DoctorMaster .Gender, DrClinicDetails .Address,
    DoctorMaster.Te lephone+',' +DoctorMaster.M obile as Phone,
    PrimaryTitle.Pr imaryTitle
    from DoctorMaster,Dr ClinicDetails,P rimaryTitle,Spe cialt y
    where (DoctorMaster.D RID=DrClinicDet ails.DRID and
    DoctorMaster.SP ID=Specialty.SP ID and
    PrimaryTitle.PT ID=DoctorMaster .PrimaryTitleID ) AND
    (DoctorMaster.F irstName like @FirstName + '%' or
    Specialty.Speci alty = @Specialty or
    DoctorMaster.Ci ty = @City )

    END

    To execute the procedure
    Exec Pro_Grid 'firstname','sp eciality','city '

    Comment

    Working...