select
FIO.NAME_TEXT "ФИО пользователя",
HR0.STEXT "Подразделение человека, который зашел в объект",
LOG.OBJ_DIVISION "Подразделение объекта в который зашли",
LOG.OBJ_EXT "ID(ключ) объекта",
LOG.BP_NAME "Наименование клиента",
LOG.OBJ_STATUS "Статус объекта",
LOG.LOG_STAMP "Метка времени"
from crt.ZLOGGING_LOG as LOG
inner join crt.V_SOUCADCP as FIO on FIO.MANDT=LOG.CLIENT
and FIO.SAPNAM=LOG.LOG_UNAME
inner join crt.HRP1001 as HR1 on HR1.MANDT=LOG.CLIENT
and HR1.SOBID=LOG.LOG_UNAME
and HR1.OTYPE='CP'
and HR1.PLVAR='01'
and HR1.ENDDA='99991231'
inner join crt.HRP1001 as HR2 on HR2.MANDT=LOG.CLIENT
and HR2.SOBID=HR1.OBJID
and HR2.OTYPE='S'
and HR2.PLVAR='01'
and HR2.ENDDA='99991231'
inner join crt.HRP1001 as HR3 on HR3.MANDT=LOG.CLIENT
and HR3.SOBID=HR2.OBJID
and HR3.OTYPE='O'
and HR3.PLVAR='01'
and HR3.ENDDA='99991231'
inner join crt.HRP1000 as HR0 on HR0.MANDT=LOG.CLIENT
and HR0.OBJID=HR3.OBJID
and HR0.OTYPE='O'
and HR0.PLVAR='01'
and HR0.ENDDA='99991231'
where LOG.CLIENT='001'
LOG_STAMP
будет select скажем за период в последний месяц. DATEADD
и GETDATE
, но пока безуспешно. SELECT
FIO.NAME_TEXT AS "ФИО пользователя",
HR0.STEXT AS "Подразделение человека, который зашел в объект",
LOG.OBJ_DIVISION AS "Подразделение объекта в который зашли",
LOG.OBJ_EXT AS "ID(ключ) объекта",
LOG.BP_NAME AS "Наименование клиента",
LOG.OBJ_STATUS AS "Статус объекта",
LOG.LOG_STAMP AS "Метка времени"
FROM crt.ZLOGGING_LOG AS LOG
INNER JOIN crt.V_SOUCADCP AS FIO ON FIO.MANDT = LOG.CLIENT
AND FIO.SAPNAM = LOG.LOG_UNAME
INNER JOIN crt.HRP1001 AS HR1 ON HR1.MANDT = LOG.CLIENT
AND HR1.SOBID = LOG.LOG_UNAME
AND HR1.OTYPE = 'CP'
AND HR1.PLVAR = '01'
AND HR1.ENDDA = '99991231'
INNER JOIN crt.HRP1001 AS HR2 ON HR2.MANDT = LOG.CLIENT
AND HR2.SOBID = HR1.OBJID
AND HR2.OTYPE = 'S'
AND HR2.PLVAR = '01'
AND HR2.ENDDA = '99991231'
INNER JOIN crt.HRP1001 AS HR3 ON HR3.MANDT = LOG.CLIENT
AND HR3.SOBID = HR2.OBJID
AND HR3.OTYPE = 'O'
AND HR3.PLVAR = '01'
AND HR3.ENDDA = '99991231'
INNER JOIN crt.HRP1000 AS HR0 ON HR0.MANDT = LOG.CLIENT
AND HR0.OBJID = HR3.OBJID
AND HR0.OTYPE = 'O'
AND HR0.PLVAR = '01'
AND HR0.ENDDA = '99991231'
WHERE LOG.CLIENT = '001'
AND CONVERT(DATETIME,
SUBSTRING(CAST(LOG.LOG_STAMP AS VARCHAR(14)), 1, 4) + '-' +
SUBSTRING(CAST(LOG.LOG_STAMP AS VARCHAR(14)), 5, 2) + '-' +
SUBSTRING(CAST(LOG.LOG_STAMP AS VARCHAR(14)), 7, 2) + ' ' +
SUBSTRING(CAST(LOG.LOG_STAMP AS VARCHAR(14)), 9, 2) + ':' +
SUBSTRING(CAST(LOG.LOG_STAMP AS VARCHAR(14)), 11, 2) + ':' +
SUBSTRING(CAST(LOG.LOG_STAMP AS VARCHAR(14)), 13, 2)
, 120) >= DATEADD(MONTH, -1, GETDATE())