title: How to set query value to output variable in stored procedure
body: <p>Here is my SQL query, when I execute it, the error shown below is occurring. I am new to SQL Server, can anyone explain what the reason for this error is? How can I set this SQL JOIN query to variable?</p>
  
  <pre><code>ALTER PROC spGetFullLog
      @PatientID varchar(10),
      @PatientD nvarchar(255) output
  WITH ENCRYPTION
  AS
  BEGIN
      SELECT 
          @PatientD = First_Name,
          Last_Name,
          dbo.CalculateAge(Date_of_Birth) AS Age,
          Admitted_Date, Patient_Condition,
          Medicine_Prescribed, Treatment_Advice,
          Treatments_Given, Date_of_Discharged,
          Diagnosis, Treatments,
          Date_of_operation, Typpe_of_operation,
          Condition_Before, Condition_After
      FROM 
          Patients_Main
      FULL JOIN
          Admitted_Patients ON Patients_Main.Patient_ID = Admitted_Patients.Patient_ID
      LEFT JOIN
          Discharged_Patients ON Patients_Main.Patient_ID = Discharged_Patients.Patient_ID
      LEFT JOIN 
          Patient_Consultation_Details ON Patients_Main.Patient_ID = Patient_Consultation_Details.Patient_ID
      LEFT JOIN 
          Operation ON Patients_Main.Patient_ID = Operation.Patient_ID
      LEFT JOIN
          Patient_Conditon ON Patients_Main.Patient_ID = Patient_Conditon.Patient_ID
      WHERE
          Patients_Main.Patient_ID = @PatientID
  END
  </code></pre>
  
  <p>This is the code I used to execute this stored procedure </p>
  
  <pre><code>DECLARE @Details nvarchar(255)
  EXECUTE spGetFullLog 'PT0001', @Details output
  print @Details
  </code></pre>
  
  <p>This is the error </p>
  
  <blockquote>
    <p>Msg 141, Level 15, State 1, Procedure spGetFullLog, Line 7<br>
    A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.</p>
  </blockquote>