Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何检查存储过程中的密码到期列是否只剩下14,7,3,2,1天?_Sql Server - Fatal编程技术网

Sql server 如何检查存储过程中的密码到期列是否只剩下14,7,3,2,1天?

Sql server 如何检查存储过程中的密码到期列是否只剩下14,7,3,2,1天?,sql-server,Sql Server,我有一个sp,我检查用户的密码更改日期是否有14天 左(flag=0),我向该用户发送电子邮件,并检查sp(通过 col.flag)如果电子邮件已发送或未发送。之后,我将更新 另一个SP(ExpiryNotificationFlag)中的标志列,指向其电子邮件已被 已经发送..现在我不知道如何检查7,3,2,1天作为标志 col值已为1 sp SELECT TenantName , TenantEmail , GMAP_

我有一个sp,我检查用户的密码更改日期是否有14天 左(
flag=0)
,我向该用户发送电子邮件,并检查sp(通过 col.flag)如果电子邮件已发送或未发送。之后,我将更新 另一个SP(
ExpiryNotificationFlag
)中的标志列,指向其电子邮件已被 已经发送..现在我不知道如何检查7,3,2,1天作为标志 col值已为1

sp

        SELECT  TenantName
              , TenantEmail 
              , GMAP_code
              , ContactID       FROM (
                SELECT    b_1.TenantName
                        , b_1.TenantEmail
                        , LastPDWChangeDate =(SELECT ISNULL(max (DateChanged),GETDATE()) FROM dbo.wsm_Contact_PwdHistory WHERE ContactID = b_1.TenantRegContactID)
                        , ExpiryNotificationFlag =(SELECT top 1 ExpiryNotificationFlag FROM dbo.wsm_Contact_PwdHistory WHERE ContactID = b_1.TenantRegContactID order by DateChanged desc)
                        , GMAP_code =(SELECT TOP 1 ISNULL(GMAP_CODE,'') from wsm_Ref_Buildings where BuildingId = b_1.BuildingID)
                        , b_1.TenantRegContactID as ContactID
                FROM     dbo.wsm_Contact AS a LEFT OUTER JOIN  
                (
                    SELECT C.Name AS TenantName
                        , A.SiteID
                        , A.BuildingID
                        , A.FloorID
                        , A.ContactID AS TenantRegContactID
                        , D.LEASID
                        , C.Phone AS TenantPhone
                        , C.Email AS TenantEmail
                        , B.UserID AS userid
                        , C.Mobile AS TenantMobile 
                        , B.UserType 
                    FROM  dbo.wsm_Contact_Tenancy AS A 
                    INNER JOIN  dbo.wsm_Contact_User AS B ON A.ContactID = B.ContactID AND B.Active = 1  
                    INNER JOIN  dbo.wsm_Contact AS C ON B.ContactID = C.ContactID 
                    INNER JOIN  (
                            SELECT DISTINCT COALESCE (LEASID, ExtLeasNum) AS LEASID
                                , SiteID
                                , BuildingID
                                , FloorID  
                            FROM  dbo.wsm_Contact) AS D ON A.SiteID = D.SiteID AND A.BuildingID = D.BuildingID AND A.FloorID = D.FloorID) AS b_1 ON   
                                COALESCE (a.LEASID, a.ExtLeasNum) = b_1.LEASID AND a.SiteID = b_1.SiteID AND a.BuildingID = b_1.BuildingID AND a.FloorID = b_1.FloorID 
                            INNER JOIN  dbo.wsm_Ref_Floors AS C ON a.FloorID = C.FloorId  
                            WHERE (a.OCCPSTAT NOT IN ('I', 'P')) and C.Deleted = 0 and b_1.userid is not null       ) AS A WHERE   DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 76 AND ISNULL(ExpiryNotificationFlag,0) <> 1

END

你基本上是在抱怨:

“布尔数据类型只能存储两个值中的一个!”

事实上,所以将该标志替换为“剩余天数”列,并将其与14、7等进行比较

请注意,ExpiryNotificationFlag列不是一个好名字-PasswordExpiryEmailSent怎么样


有时候,当列的名称更好时,这些问题就更容易考虑了。你可以这样做

( (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 76 AND ISNULL(ExpiryNotificationFlag,0) = 0)  --14 days      

  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 83 AND ISNULL(ExpiryNotificationFlag,0) = 1) --7days      

  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 87 AND ISNULL(ExpiryNotificationFlag,0) = 2) --3 days      

  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 88 AND ISNULL(ExpiryNotificationFlag,0) = 3) --2 days      
  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 89 AND ISNULL(ExpiryNotificationFlag,0) = 4) --1 day      

  )  
为此,您必须将到期通知标志修改为int,而不是布尔值
之后,创建一个SP,u将从中更新值 0到1、1到2、2到3等

( (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 76 AND ISNULL(ExpiryNotificationFlag,0) = 0)  --14 days      

  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 83 AND ISNULL(ExpiryNotificationFlag,0) = 1) --7days      

  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 87 AND ISNULL(ExpiryNotificationFlag,0) = 2) --3 days      

  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 88 AND ISNULL(ExpiryNotificationFlag,0) = 3) --2 days      
  or (DATEDIFF(DAY,A.LastPDWChangeDate,getdate()) = 89 AND ISNULL(ExpiryNotificationFlag,0) = 4) --1 day      

  )