sql >> Database teknologi >  >> RDS >> Sqlserver

Kan du ikke bruge midlertidig kolonne i hvor-klausulen?

En løsning ville være at foretage et undervalg af hele sætningen ved at anvende where-sætningen på resultatet

select  *
from    (
          select  cast(de.ApprovalOrder AS VARCHAR(32)) 
                  + cast(de.EntityCode AS VARCHAR(32)) 
                  + isnull(cast(de.DelegationCode AS VARCHAR(32)), '') as 'RowID'
                  , *
          from    workflow.delegation_engine de
        ) de 
where   de.RowID IS NOT NULL

En anden løsning kunne være at gentage hele klausulen i WHERE-sætningen

select  cast(de.ApprovalOrder AS VARCHAR(32)) 
        + cast(de.EntityCode AS VARCHAR(32)) 
        + isnull(cast(de.DelegationCode AS VARCHAR(32)), '') as 'RowID' ,
        *
from    workflow.delegation_engine de
where   cast(de.ApprovalOrder AS VARCHAR(32)) 
        + cast(de.EntityCode AS VARCHAR(32)) 
        + isnull(cast(de.DelegationCode AS VARCHAR(32)), '') IS NOT NULL

Eller du kan teste hvert enkelt felt for NULL

select  cast(de.ApprovalOrder AS VARCHAR(32)) 
        + cast(de.EntityCode AS VARCHAR(32)) 
        + isnull(cast(de.DelegationCode AS VARCHAR(32)), '') as 'RowID' ,
        *
from    workflow.delegation_engine de
where   de.ApprovalOrder IS NOT NULL
        AND de.EntityCode IS NOT NULL



  1. SQL Server-klynger fra et Oracle RAC-perspektiv

  2. DELETE LIMIT for flere borde

  3. Opret domæne i MySQL

  4. Forskellen på to dato-klokkeslæt i sql-server