2017-06-15 1 views
0

ich habe ein sp, die ich überprüfen, ob Kennwortänderung Datum des Benutzers 14 Tage links hat (flag=0) und ich schicken Sie diese an, dass Benutzer und ich, dass sp i überprüfen (durch eine col.flag), wenn E-Mail bereits oder nicht gesendet .nach, dass ich die Flagge col.in einem anderen SP (ExpiryNotificationFlag) zu 1 der Benutzerliste aktualisiere, deren eMail bereits sendete..now, ich weiß nicht, wie man auf 7,3,2,1 Tage als prüft flag col Wert bereits 1?Wie überprüft man, ob die Kennwortablaufspalte in einer Speicherprozedur nur noch 14,7,3,2,1 Tage hat?

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 

Update-Abfrage

UPDATE dbo.wsm_Contact_PwdHistory set ExpiryNotificationFlag = 1 WHERE ContactID = @ContactID 

Antwort

0

man es so tun können,

((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  

) 

für die u haben Verfalls Benachrichtigung Flagge ändern anstelle eines booleschen
danach in int eine SP machen wo u die va aktualisieren lue von 0 bis 1,1 bis 2,2 bis 3 usw.

0

Youre im Wesentlichen die folgende Beschwerde vorliegen:

"Ein boolean-Datentyp nur einen von zwei Werten speichern kann"

Tat also tausche dieses Flag für eine Anzahl von verbleibenden Tagen aus und vergleiche es mit 14, 7, was auch immer ....

Hinweis, ExpiryNotificationFlag Spalte ist kein großer Name - wie etwa „PasswordExpiryEmailSent“

Manchmal sind diese Probleme viel leichter zu bekommen, um darüber nachzudenken, wenn die Spalten haben bessere Namen

Verwandte Themen