DECLARE @login nvarchar(30)
-- 查询设定密码过期的登陆账号
SELECT @login = name
FROM sys.sql_logins
WHERE is_expiration_checked = 1
and name = 'test_temp'
-- 计算登录账户密码已使用天数
SELECT @login AS 'login',
DATEDIFF(d,
CAST(LOGINPROPERTY(@login,
'PasswordLastSetTime') AS datetime),
GETDATE()) AS 'pwd_using_days'
-- 计算密码到期之前的剩余天数
-- 注意,只适合于sql server 2008
SELECT LOGINPROPERTY(@login, 'DaysUntilExpiration') AS 'days_until_expiration'