Sp_error

Last post 05-08-2008 5:04 AM by dharnendra. 2 replies.

Sort Posts:

  • Sp_error

    05-03-2008, 9:06 AM

    frenz:
            i have the following  procedure:while running


              EMP_SP_EmpDetails_Display 'FirstName', 'ASC'

            i got the error like this:  Msg 170, Level 15, State 1, Line 1
                                        Line 1: Incorrect syntax near '.'.

    plz can any one solve this problem.




    My procedure:


    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:        <Author,,Name>
    -- Create date: <Create Date,,>
    -- Description:    <Description,,>
    -- =============================================
    ALTER procedure [dbo].[EMP_SP_EmpDetails_Display]
        -- Add the parameters for the stored procedure here
        (@colum as varchar(50),@order as varchar(50))
    AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;

        declare @sqlexec varchar(1500)


        -- Insert statements for procedure here
        set @sqlexec=''
        set @sqlexec=@sqlexec + 'SELECT EL.UserName,EL.Password, E.EmpID, E.FirstName, E.LastName, E.DesignationID, E.DepartmentID, E.Sex '
        set @sqlexec=@sqlexec + 'E.DOB, E.Age, E.Address, E.Email, H.Hobby,'
        set @sqlexec=@sqlexec + 'ContactNo=Case When E.phone is not null Then E.phone '
        set @sqlexec=@sqlexec + 'When E.phone is null Then  E.Mobile End, '
        set @sqlexec=@sqlexec + 'E.DateOfjoining, D.Designation, DE.Department '
        set @sqlexec=@sqlexec + 'From dbo.EMP_Tbl_Employee E '
        set @sqlexec=@sqlexec + 'Inner Join dbo.EMP_Tbl_Designation D On E.DesignationID=D.DesignationID '
        set @sqlexec=@sqlexec + 'Inner Join dbo.EMP_Tbl_Department DE On E.DepartmentID=DE.DepartmentID '
        set @sqlexec=@sqlexec + 'Inner Join dbo.EMP_Tbl_EmployeeHobbies EH On E.EmpID=EH.EmpID '
        set @sqlexec=@sqlexec + 'Inner Join  dbo.EMP_Tbl_Hobby H On E.Sno=H.Sno '
        set @sqlexec=@sqlexec + 'Inner Join dbo.EMP_Tbl_EmployeeLogin EL On E.Sno=EL.Sno order by '+@colum+' '+@order+''
    print(@sqlexec)

    END


     

    Filed under:
  • Re: Sp_error

    05-03-2008, 9:22 AM

    SET QUOTED_IDENTIFIER ON

     sometimes this helps the problem, BTW what does print command is giving the value.I guess that could help u find the problem, running the query obtained by print can actually help in solving the problem

  • Re: Sp_error

    05-08-2008, 5:04 AM

       set @sqlexec=''
        set @sqlexec=@sqlexec + 'SELECT EL.UserName,EL.Password, E.EmpID, E.FirstName, E.LastName, E.DesignationID, E.DepartmentID, E.Sex '

    Repleace with

      set @sqlexec='SELECT EL.UserName,EL.Password, E.EmpID, E.FirstName, E.LastName, E.DesignationID, E.DepartmentID, E.Sex ,'

     Seem comma error in first select statement.

    another thing

    set @sqlexec=@sqlexec + 'Inner Join dbo.EMP_Tbl_EmployeeLogin EL On E.Sno=EL.Sno order by '+@colum+'   '+@order+''

    Put some more space between column and order variable.

    Thanks 

    Shah Dharnendra G
    Analyst Programmer,
    GTL-Ahmedabad
Page 1 of 1 (3 items)