Nested Conditional (If-Else) inside stored procedure
<p>First time asking a question here. Thanks in advance for any help.</p>

<p>I'm mostly a front-end guy and sometimes get tripped up with the SQL syntax / control flow.</p>

<p>I have a stored procedure I've written that specifies a parameter (<code>@listAll</code>) to be passed in that specifies whether to list all registrations within a queue in a table for viewing.  </p>

<p>I'd like to run the <code>RQ.Processed</code>, which shows as an <code>INT</code> (0 or 1), through an IF-ELSE condition to set the 0 or 1 to a string (Not Processed / Processed). This will be populating a data table on our front end for our customers to view a registration queue.</p>

<p>However, anywhere I try to add this condition I'm getting syntax errors. I'm also assuming the variable that will be used for the data type conversion (<code>@statusConversion</code>) needs to be outside the scope of the select statements, but I may be totally off.  </p>

<p>Here is what I have so far:</p>

<pre><code>create proc [dbo].[Portal.RegistrationQueue_ListAll] 
    (@listAll int)
as
    set nocount on

    declare @statusConversion varchar(30)

    if (@listAll = 1)
    begin
        select 
            C.CompanyName as 'Company', 
            RCG.Learner_Tag as 'Registration Group', 
            convert(varchar(40), RQ.CreatedOn, 110) as 'Date', 
            RQ.Processed as 'Status'
        from 
            [dbo].[Portal.RegistrationQueue] RQ
        join 
            [dbo].[Portal.Company] C on RQ.CompanyID = C.Id
        join 
            [dbo].[Portal.RegisteredCourseGroup] RCG on RQ.RegistrationGroupID = RCG.Id
    end
    else
    begin
        select 
            C.CompanyName as 'Company', 
            RCG.Learner_Tag as 'Registration Group', 
            convert(varchar(40), RQ.CreatedOn, 110) as 'Date', 
            RQ.Processed as 'Status'
        from 
            [dbo].[Portal.RegistrationQueue] RQ
        join 
            [dbo].[Portal.Company] C on RQ.CompanyID = C.Id
        join 
            [dbo].[Portal.RegisteredCourseGroup] RCG on RQ.RegistrationGroupID = RCG.Id
        where 
            RQ.Processed = 0
    end
GO
</code></pre>

<p>What I need is help on where to place the IF-ELSE to convert the (0,1) to 'Not Processed', 'Processed' and also if I've placed that conversion variable in the right place.  </p>

<p>Thanks.</p>