I'm having problems parsing a string that is passed to this stored procedure. It works fine (creates the view) when only one StudentNumber is passed to it, but when multiple numbers are passed (separated by commas with no spaces), it returns no records. How can I do this differently?
ALTER PROCEDURE sp_SprocName
@StudentNumber varchar(500)
AS
Declare @inCriteria as Varchar(500)
Set @inCriteria = '''' + (Replace(@StudentNumber ,',',''',''' )) + ''''
declare @SQL as varchar (2000)
set @SQL = 'SELECT ... WHERE (StudentNumberField = '+@inCriteria+')'
Declare @MyView as varchar (5000)
Set @MyView ='alter view vw_ViewName as ' +@SQL
Exec (@MyView)
ALTER PROCEDURE sp_SprocName
@StudentNumber varchar(500)
AS
Declare @inCriteria as Varchar(500)
Set @inCriteria = '''' + (Replace(@StudentNumber ,',',''',''' )) + ''''
declare @SQL as varchar (2000)
set @SQL = 'SELECT ... WHERE (StudentNumberField = '+@inCriteria+')'
Declare @MyView as varchar (5000)
Set @MyView ='alter view vw_ViewName as ' +@SQL
Exec (@MyView)