Share via

TRANSACT -SQL question

rabinda77 66 Reputation points
2021-02-03T16:16:08.23+00:00

Hello,

I have the below query which returns password expiration details for sql logins.

===============================================================

SELECT @@SERVERNAME AS ServerName, SL.name AS LoginName
,LOGINPROPERTY(SL.name, 'PasswordLastSetTime') AS PasswordLastSetTime
,LOGINPROPERTY(SL.name, 'DaysUntilExpiration') AS DaysUntilExpiration
,DATEADD(dd, CONVERT(int, LOGINPROPERTY(SL.name, 'DaysUntilExpiration'))
CONVERT(int, LOGINPROPERTY(SL.name, 'PasswordLastSetTime'))) AS PasswordExpirationDate,

CASE
WHEN is_expiration_checked = 1 THEN 'TRUE' ELSE 'FALSE'
END AS PasswordExpireChecked

FROM sys.sql_logins AS SL

WHERE SL.name NOT LIKE '##%' AND SL.name NOT LIKE 'endPointUser' and is_disabled = 0

ORDER BY (LOGINPROPERTY(SL.name, 'PasswordLastSetTime') DESC

=================================================================

If PasswordExpireChecked value is FALSE,

I want the values for DateUntilExpiration and PasswordExpirationDate set to 'NEVER EXPIRE'

Please help me

Thank you

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

0 comments No comments

Answer accepted by question author

Tom Phillips 17,786 Reputation points
2021-02-03T17:31:29.17+00:00
SELECT @@SERVERNAME AS ServerName, SL.name AS LoginName
,LOGINPROPERTY(SL.name, 'PasswordLastSetTime') AS PasswordLastSetTime
,ISNULL(CONVERT(varchar(100),LOGINPROPERTY(SL.name, 'DaysUntilExpiration')),'Never Expire') AS DaysUntilExpiration
,ISNULL(CONVERT(varchar(100),DATEADD(dd, CONVERT(int, LOGINPROPERTY(SL.name, 'DaysUntilExpiration')),CONVERT(int, LOGINPROPERTY(SL.name, 'PasswordLastSetTime'))),101),'Never Expire') AS PasswordExpirationDate,

CASE
WHEN is_expiration_checked = 1 THEN 'TRUE' ELSE 'FALSE'
END AS PasswordExpireChecked

FROM sys.sql_logins AS SL

WHERE SL.name NOT LIKE '##%' AND SL.name NOT LIKE 'endPointUser' and is_disabled = 0

ORDER BY (LOGINPROPERTY(SL.name, 'PasswordLastSetTime')) DESC

Was this answer helpful?


3 additional answers

Sort by: Most helpful
  1. EchoLiu-MSFT 14,626 Reputation points
    2021-02-04T07:22:04.473+00:00

    Glad your problem is solved.
    If you have any question, please feel free to let me know.

    Regards
    Echo

    Was this answer helpful?


  2. EchoLiu-MSFT 14,626 Reputation points
    2021-02-04T07:21:30.073+00:00

    Glad your problem is solved.

    If you have any question, please feel free to let me know.

    Regards
    Echo

    Was this answer helpful?

    0 comments No comments

  3. Dan Guzman 9,516 Reputation points
    2021-02-03T17:32:25.543+00:00

    Execute:

    ALTER LOGIN YourLogin WITH CHECK_EXPIRATION=OFF;
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.