TSQL to get a list of all users and when they last logged on in crowddb We have a crowddatabase and are trying to get a list of every user and when they last logged on. On Atlassians website there is a query but only for MySQL, the query is: 

SELECT 
  cwd_user.user_name, 
  from_unixtime(cwd_user_attribute.attribute_value/1000) 
FROM cwd_user, cwd_user_attribute 
WHERE cwd_user_attribute.user_id = cwd_user.id 
  AND cwd_user_attribute.attribute_name = 'lastAuthenticated'


I need to rewrite it for mssql and tried with

SELECT 
  cwd_user.user_name, 
  dateadd(s,12345,1/1/1970) 
  select cwd_user_attribute.attribute_value 
FROM cwd_user, cwd_user_attribute 
WHERE cwd_user_attribute.user_id = cwd_user.id 
  AND cwd_user_attribute.attribute_name = 'lastAuthenticated'


but get error The multi-part identifier "cwd_user.user_name" could not be bound.

Anyone who can help with the query?
You have an extra SELECT in your SQL.

Remove the SELECT and change the DATEADD function slightly.

SELECT 
  cwd_user.user_name, 
  DATEADD(SECOND,(CAST(cwd_user_attribute.attribute_value AS BIGINT)/1000),'1970-01-01')
FROM cwd_user, cwd_user_attribute 
WHERE cwd_user_attribute.user_id = cwd_user.id 
  AND cwd_user_attribute.attribute_name = 'lastAuthenticated';


Additionally, you should probably rewrite to support the 'new' JOIN syntax (by 'new', I mean ANSI-92)

SELECT 
  cwd_user.user_name, 
  DATEADD(SECOND,(CAST(cwd_user_attribute.attribute_value AS BIGINT)/1000),'1970-01-01')
FROM cwd_user
INNER JOIN cwd_user_attribute 
   ON cwd_user_attribute.user_id = cwd_user.id 
  AND cwd_user_attribute.attribute_name = 'lastAuthenticated';