title: Must Declare the scalar variable error in Stored Procedure
body: <pre><code>ALTER PROCEDURE [dbo].[SP_GetLatestMmdData]
  
  AS
  DECLARE
       @vReturnVar VARCHAR(10) 
      ,@vRCount VARCHAR(10)
  BEGIN
  
  SET NOCOUNT ON;
  SET @vRCount =(SELECT Distinct Shift From [dbo].[tblMMDLogEntry] Where Shift Like 'Night     ' And Date=(SELECT  MAX(Date)  
                  FROM [dbo].[tblMMDLogEntry]))
  IF(@vRCount&gt;0) 
  BEGIN
      SET @vReturnVar='Night      '
  END
  Else
  BEGIN
      SET @vReturnVar='Evening    '
  END             
  
  SELECT
      convert(varchar,[Date],103) Date
                      ,Shift
                      ,SlNo
                      ,TotalManpower
                      ,JobDescription
                      ,PermitNo
                      ,StartTime
                      ,EndTime
                      ,AllotedManpower
                      ,Supervisior
                      ,AShift
                      ,GShift
                      ,BShift
                      ,CShift
                      ,Remarks 
      FROM [dbo].[tblMMDLogEntry] WHERE Date=(SELECT  MAX(Date)  
       FROM [dbo].[tblMMDLogEntry]) 
       AND Shift= @vReturnVar 
  
  END
  </code></pre>
  
  <p>I have the Following Code in My stored Procedure. i have already declared that @vReturnVar
  but still showing 'Must Declare the scalar variable "@vReturnVar".</p>