Search code examples
sql-serverdatabaseautocompleteprocedure

MS SQL server error while making a procedure


I simply want to get a procedure which displays names which start with letters Up (I'm trying to make an Auto complete for ASP.NET)

select * from Diagnose

Create proc spGetNames 'Up'
@term nvarchar (50)
as
Begin
    Select Name
    from Diagnose
    where Name like @term + '%'
End

But this error keeps poping out:

Msg 102, Level 15, State 1, Procedure spGetNames, Line 3 [Batch Start Line 0]
Incorrect syntax near 'Up'.
Msg 137, Level 15, State 2, Procedure spGetNames, Line 9 [Batch Start Line 0]
Must declare the scalar variable "@term".

On youtube people did the same as me and it worked for them: enter image description here

Any tips would be great :)


Solution

    1. Remove 'Up' when you create Procedure

      Create proc spGetNames
      @term nvarchar (50)
      as
      Begin
          Select Name
          from Diagnose
          where Name like @term + '%'
      End

    2. Execute your procedure like following

      exec spGetNames 'Up'