Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

DB script for searching active users

Erwin Manuel
Contributor
January 13, 2013

We would like to query for users whose last login was within 1 year from current date.

I found this query from docs:

SELECT
u.username AS username ,
psname.propertyvalue AS FullName ,
psemail.propertyvalue AS email,
pslogincount.propertyvalue AS logincount,
to_timestamp(pslastlogin.propertyvalue::numeric /1000) AS lastlogin
FROM
userbase u
JOIN
(
SELECT
id,
entity_id
FROM
propertyentry
WHERE
property_key = 'fullName'
)
entityName
ON
u.id = entityName.entity_id
JOIN
(
SELECT
id,
entity_id
FROM
propertyentry
WHERE
property_key = 'email'
)
entityEmail
ON
u.id = entityEmail.entity_id
left JOIN
(
SELECT
id,
entity_id
FROM
propertyentry
WHERE
property_key = 'login.count'
)
loginCount
ON
u.id = loginCount.entity_id
left JOIN
(
SELECT
id,
entity_id
FROM
propertyentry
WHERE
property_key = 'login.previousLoginMillis'
)
lastLogin
ON
u.id = lastLogin.entity_id
JOIN propertystring psname
ON
entityName.id=psname.id
JOIN propertystring psemail
ON
entityEmail.id = psemail.id
left JOIN propertystring pslogincount
ON
loginCount.id=pslogincount.id
left JOIN propertystring pslastlogin
ON
lastLogin.id = pslastlogin.id
ORDER BY username;
This seems to be what we need but the line "to_timestamp(pslastlogin.propertyvalue::numeric /1000) AS lastlogin" is not accepted in sql server. Does anyone knows whae query we can use to replace this line? Thanks in advance

2 answers

1 accepted

0 votes
Answer accepted
Erwin Manuel
Contributor
January 20, 2013

I found the solution with the help of Atlassian support.

The equivalent in SQL of:

to_timestamp(pslastlogin.propertyvalue::numeric /1000) AS lastlogin

Is

dateadd(ss, cast( cast(pslastlogin.propertyvalue as varchar(1000)) as numeric) / 1000,'01/01/1970') as lastlogin

0 votes
Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 19, 2013
Erwin Manuel
Contributor
January 20, 2013

I got: 'Arithmetic overflow error converting expression to data type datetime.'

Looks like its not what I need.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events