Note that there are some explanatory texts on larger screens.

plurals
  1. POCase within Case statement
    text
    copied!<p>I have to get an instructor approval date from a table called section. If that table doesn't have the date (null), then I have to get a date from offering table, and even if that table doesn't have what I am looking for, then from Term table.</p> <p>AND if all three are null, then I need to get absoluteExpireDate in same manners as instructorapprovaldate.</p> <p>AND if absoluteExpireDate is also null in all three tables, then I need to get WaitList date in similar fashion.</p> <p>How do I create a case statement to handle that?</p> <p>so far here's what I have:</p> <pre><code>SELECT @dInstructApprDate = case when a.InstructorApprovalDate is null then select @dInstructApprDate = instructorapprovaldate from SSS_OfferingAcademicPeriods where SSS_OfferingRegPeriods.SSS_OfferingsID = @lSSS_OfferingsID </code></pre> <p>I am not sure why it doesn't like me using select statement within "THEN"</p> <p>Any help would be appreciated.</p> <p>Here is what I got so far for the function:</p> <pre><code> CREATE FUNCTION [dbo].[SSS_GetInstructorApprovalDate](@lSSS_SectionsID INT) RETURNS VARCHAR(20) AS BEGIN DECLARE @dInstructApprDate DATETIME, @dAddDropDate DATETIME, @lTemp INT, @lSSS_OfferingsID INT, @lSSS_TermsID INT SET @lTemp = 0 SELECT @lTemp = 1 WHERE EXISTS (SELECT 1 FROM SSS_SectionAcademicPeriods WITH (NOLOCK) WHERE SSS_SectionsID = @lSSS_SectionsID) --Fetch from section level, if present - Begin IF @lTemp = 1 BEGIN SELECT @dInstructApprDate = case when a.InstructorApprovalDate is null then (select instructorapprovaldate from SSS_OfferingAcademicPeriods where SSS_OfferingRegPeriods.SSS_OfferingsID = @lSSS_OfferingsID) else InstructorApprovalDate end FROM SSS_SectionAcademicPeriods a WITH (NOLOCK) where SSS_SectionsID = @lSSS_SectionsID </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload