[SQL] queries the records used by a field in the database for a certain period of time.
Sometimes we often need to use some tables or execute a stored procedure. Sort out the SQL queries executed by the database in a certain period of time. You can also query the storage of some fields in the database. Very good, very powerful, hope to help you ~
Select top 1000 -- Creation Time QS. creation_time, -- query statement SUBSTRING (ST. text, (QS. statement_start_offset/2) + 1, (case qs. statement_end_offset WHEN-1 then datalength (st. text) else qs. statement_end_offset END-QS. statement_start_offset)/2) + 1) AS statement_text, -- execute the text ST. text, -- execution plan QS. total_worker_time, QS. last_worker_time, QS. max_worker_time, QS. min_worker_time FROM sys. dm_exec_query_stats QS -- Keyword cross apply sys. dm_exec_ SQL _text (QS. SQL _handle) ST WHERE QS. creation_time BETWEEN '2017-12-2013: 00: 00' AND '2017-12-03 11:00:00 'and st. text LIKE '% BK_TSESTATU %' order by qs. creation_time
In the following code, BK_TSESTATU is the field for fuzzy search.
ST.text LIKE '%BK_TSESTATU%'
SQLserver2005
Select CONVERT (varchar (12), Date Field, 112), sum (accumulate field) from table name where Date Field between'2017-01-01 'and '2017-01-31' group by CONVERT (varchar (12), Date Field, 2013)
I used the date range from January 1-1 to 31. Change it by yourself.
How to use SQL statements to query duplicate rows of a specific field in the database
I usually use this:
Assume that the repeated field names are suspected to be SeriNo,
Select * from [tablename]
Group by SeriNo
Having count (SeriNo) <> 1