With help from techgnome and szlamany I am attempting to write a SPROC that will accept a delimited string (ie: Office 1,Office 2,Office 3) as a parameter. So after reviewing this POST by szlamany, I attempted to create a SPROC:

VB Code:
  1. GO
  2. CREATE PROCEDURE dbo.TestSP
  3.     /*Declare Variables*/
  4.     @ListStr varchar(100) /*Hold Delimited String*/
  5.     @ListTbl Table (InvUnit varchar(50)) /*Creates Temp Table*/
  6.     @CP int /*Len of String */
  7.     @SV varchar(50) /*Holds Result */
  8.  
  9. AS
  10.  
  11. While @ListStr<>''
  12. Begin
  13.     Set @CP=CharIndex(',',@ListStr) /*Sets length of words - Instr */
  14.     If @CP<>0
  15.     Begin
  16.         Set @SV=Cast(Left(@ListStr,@CP-1) as varchar) /*Copies Portion of String*/
  17.         Set @ListStr=Right(@ListStr,Len(@ListStr)-@CP) /*Sets up next portion of string*/
  18.     End
  19.     Else
  20.     Begin
  21.         Set @SV=Cast(@ListStr as varchar)
  22.         Set @ListStr=''
  23.     End
  24.     Insert into @ListTbl Values (@SV) /*Inserts variable into Temp Table*/
  25. End

But when I run it I get the following errors:

Msg 102, Level 15, State 1, Procedure TestSP, Line 5
Incorrect syntax near '@ListTbl'.
Msg 137, Level 15, State 2, Procedure TestSP, Line 9
Must declare the scalar variable "@ListStr".
Msg 137, Level 15, State 2, Procedure TestSP, Line 11
Must declare the scalar variable "@ListStr".
Msg 137, Level 15, State 2, Procedure TestSP, Line 12
Must declare the scalar variable "@CP".
Msg 137, Level 15, State 2, Procedure TestSP, Line 14
Must declare the scalar variable "@ListStr".
Msg 137, Level 15, State 2, Procedure TestSP, Line 15
Must declare the scalar variable "@ListStr".
Msg 137, Level 15, State 2, Procedure TestSP, Line 19
Must declare the scalar variable "@ListStr".
Msg 137, Level 15, State 1, Procedure TestSP, Line 20
Must declare the scalar variable "@ListStr".
Msg 1087, Level 15, State 2, Procedure TestSP, Line 22
Must declare the table variable "@ListTbl".

I don't understand these error, does anyone have any ideas?


P.S. I want this SPROC to run against either a MSSQL 7.0 or MSSQL 2005 Database.
Thanks!