title: Passing comma delimited parameter to stored procedure in SQL
body: <p>If I pass call my stored procedure from T-SQL:</p>
  
  <pre><code>exec [dbo].[StoredProcedureName] '''Vijay'', ''Rana'', 1, 0'
  </code></pre>
  
  <p>in SQL Server Mgmt Studio, it works fine but when I call it from my application it gives me error </p>
  
  <blockquote>
    <p>Unclosed quotation mark after the character string ''Vijay','Rana',1,0'.</p>
  </blockquote>
  
  <p>I searched on the google and find this <code>EXEC  sp_executesql @FinalQuery</code> but its not working for me</p>
  
  <p><strong>EDIT</strong><br>
  I am calling it like </p>
  
  <pre><code>public virtual IDataReader ImportFirefighter(String  query)
  {
          Database database = DatabaseFactory.CreateDatabase();
          DbCommand command = database.GetStoredProcCommand("[StoreProcedureName]");
          database.AddInParameter(command, "@query", DbType.String, query);
  
          IDataReader reader = null;
  
          try
          {
              reader = database.ExecuteReader(command);
          }
          catch (DbException ex)
          {
              throw new DataException(ex);
          }
  
          return reader;
      }
  </code></pre>
  
  <p><strong>EDIT</strong> My complete Store Procedure</p>
  
  <pre><code>-- =============================================          
  -- Author:  &lt;Author,,Name&gt;          
  -- Create date: &lt;Create Date,,&gt;          
  -- Description: &lt;Description,,&gt;          
  -- =============================================         
  
  --[dbo].[ImportIntoFirefighter]  '''Vijay'',''Rana'',''AC'',''AC'',''VOL'',1,0,0,1,1,''NA'','''',''VOL'','''','''',0,'''','''',0,1,1,'''',0&amp;''Vijay21'',''Rana2'',''AC'',''AC'',''VOL'',1,0,0,1,1,''NA'','''',''VOL'','''','''',0,'''','''',0,1,1,'''',0&amp;''Vijay32'',''Rana3'',''AC'',''AC'',''VOL'',1,0,0,1,1,''NA'','''',''VOL'','''','''',0,'''','''',0,1,1,'''',0&amp;''Vijay42'',''Rana4'',''AC'',''AC'',''VOL'',1,0,0,1,1,''NA'','''',''VOL'','''','''',0,'''','''',0,1,1,'''',0'  
  
  
  ALTER PROCEDURE [dbo].[ImportIntoFirefighter]         
  @query VARCHAR(MAX)          
  
  AS          
  BEGIN         
  DECLARE @TotalRecord int          
  DECLARE @loopcount int          
  DECLARE @TempQueryList TABLE                
    (             
    [ID] INT IDENTITY(1,1),                        
       [VALUE] VARCHAR(1000)                
     )           
  
  DECLARE @Result TABLE                
    (             
    [iff_id] INT IDENTITY(1,1),                        
       [last_name] VARCHAR(50),        
       [first_name] VARCHAR(50),        
       [email] VARCHAR(50),        
       [mobile_number] VARCHAR(50),        
       [error] VARCHAR(max)              
     )           
  
  
     insert into @TempQueryList (VALUE) (           
     SELECT SUBSTRING('&amp;' + @query + '&amp;', Number + 1,          
      CHARINDEX('&amp;', '&amp;' + @query + '&amp;', Number + 1) - Number -1)AS VALUE          
      FROM master..spt_values          
      WHERE Type = 'P'          
      AND Number &lt;= LEN('&amp;' + @query + '&amp;') - 1          
      AND SUBSTRING('&amp;' + @query + '&amp;', Number, 1) = '&amp;' )          
  
   Set @TotalRecord = (select count(*) FROM @TempQueryList)                   
  
    --select * from @TempQueryList          
     --Loop For Each Repeated Schedule           
   set  @loopcount = 1          
   WHILE @loopcount &lt;= @TotalRecord            
    BEGIN          
  
    Declare @SingleQuery varchar(1000)        
    select @SingleQuery = Value  from @TempQueryList where id = @loopcount          
  
     BEGIN TRY        
     --print '[AddFirefighter] '  +  @SingleQuery        
     --SELECT 1/0;        
  
      --execute (@SingleQuery)    
  
      declare @FinalQuery varchar(max)   
  
     -- Select @SingleQuery =  LEFT(RIGHT(@SingleQuery, len(@SingleQuery)-1),len(@SingleQuery)-2)  
  
  
      set @FinalQuery = '[AddFirefighter] ' +  @SingleQuery  
          print  @FinalQuery  
  
  
  
  
    EXEC  (@FinalQuery)   
  
  
     END TRY        
     BEGIN CATCH        
     insert into @Result (last_name,first_name,email,mobile_number,error) values ( '','','','',ERROR_MESSAGE() )         
     -- Execute the error retrieval routine.            
     END CATCH         
  
    --print @loopcount          
    SET @loopcount = @loopcount + 1          
  
    END          
  
    select * from @Result        
  
  --execute (@query)          
  END 
  </code></pre>