Database view - records created today in where clause

tonynys
Kilo Explorer

I try to filter records created today, mixing in mysql functions in the where clause of the table

ct.sys_created_on > DATE_ADD(NOW(),INTERVAL -1 DAY) and ct.sys_created_on < DATE_ADD(NOW(),INTERVAL 1 DAY)

For some reason EMPTY created dates are returned and the join with my sys_user_group query where condition is not happening anymore

1 REPLY 1

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Tony,



The "where clause" you see in a database view in instance UI refers to a join condition, and it's not the real SQL WHERE clause. Currently you cannot add a real SQL WHERE clause in a database view (but you can filter a database view if you add it into a report).



An example will probably clarify what I mentioned above:



- example on MySQL on the join condition:



SELECT t1.name, t2.salary


  FROM employee AS t1 INNER JOIN info AS t2 ON t1.name = t2.name;



- example on MySQL on the join condition plus a WHERE clause:



SELECT left_tbl.*


  FROM left_tbl LEFT JOIN right_tbl ON left_tbl.id = right_tbl.id


  WHERE right_tbl.id IS NULL;



Hope this helps.



Regards,
Sergiu