title: SQL Clauses for Columns within Views
body: <p>I am looking at building a view which has clauses with the column, so if certain parameters are met, then it will set a flag as 1.
  I am not sure if I am misunderstanding how a case works in this scenario, however this is what I have:</p>
  <pre><code>select t.[Ticket_ClientId] as ClientID
        ,t.[Ticket_CallerId] as CallerID
        ,t.[Ticket_RecordTypeId] as RecordTypeID
        ,t.[Ticket_Id] as TicketRawID
        ,t.[Ticket_OwnerId] as TicketOwner
        ,t.[Ticket_LocationId] as LocationID
        ,t.[Ticket_LastActionId] as LastAction
        ,t.[Ticket_OpenDate] as OpenDate
        ,t.[Ticket_CloseDate] as CloseDate
        ,t.[Ticket_LastModifiedDate] as LastModified
        ,t.[Ticket_LocationName] as LocationName
        ,t.[Ticket_Solution] as Solution
        ,t.[Ticket_PriorityName] as [Priority]
        ,t.[Ticket_TakenByName] as TakenBy
        ,t.[Ticket_GroupName] as [Group]
        ,t.[Ticket_ClientName] as Client
        ,t.[Ticket_StatusName] as [Status]
        ,t.[Ticket_DisplayId] as TicketID
        ,t.[Ticket_CallerName] as [Caller]
        ,t.[Ticket_CallerPhone] as CallerPhone
        ,t.[Ticket_CallerEmail] as CallerEmail
        ,t.[Ticket_Description] as [Description]
        ,t.[Ticket_RecordTypeNameSingular] as RecordType
        ,t.[Ticket_Title] as Title
        ,t.[Ticket_CloseSLATargetDate] as TargetClose
        ,t.[Ticket_CloseSLATimeRemaining] as CloseTimeRemaining
        ,t.[Ticket_CloseSLACompleteDate] as CloseCompleteDate
        ,t.[Ticket_NextSLATargetDate] as NextSLATarget
        ,t.[Ticket_Resolved] as Reolved
        ,t.[Ticket_ResolvedDate] as ResolvedDate
        ,t.[Ticket_CloseSLADurationOnComplete] as CloseSLADurationComplete
        ,t.[Ticket_WithinResponseSLA] as WithinResponseSLA
        ,t.[Ticket_WithinDiagnoseSLA] as WithinDiagnoseSLA
        ,t.[Ticket_WithinCloseSLA] as WithinCloseSLA
        ,t.[Ticket_WithinNextSLA] as WithinNextSLA
        ,t.[Ticket_CloseSLATargetDuration] as CloseSLATargetDuration
        ,t.[Ticket_CloseSLAElapsedTime] As CloseSLAElapsedTime
        ,t.[Ticket_UpdateDate] As [Update]
        ,t.[Ticket_CreatedByCallerName] as CreatedBy
        ,t.[Ticket_CategoryName] as QueueName
        ,t.[Ticket_PortalName] as PortalName
        ,case t.[TicketOpen]  when t.ticket_closedate is null and ticket_opendate is not null then 1 else 0 end
        ,case t.[TicketClosed] when t.ticket_closedate is not null and ticket_opendate is null then 1 else 0 end
  from dbo.Ticket t
  where cast(t.Ticket_LastModifiedDate as date) &gt;= cast(getdate()-7 as date)
  </code></pre>
  <p>I have tried to move the case clauses below my where clause however that did not work either.</p>
  <p>Please can someone advise.
  Thanks</p>