I need some help with the following query:
DECLARE @SRV VARCHAR(20), @date smalldatetime
SET @SRV = (select @@servername)
SET @date = '20040901'
select Srv_Name = @SRV, DB_Name = 'DB_NAME', Table_Name =
'Info_Table', Date_of_Records = @date,
count(*) AS 'Actual Total' ,
max (SER_NO)- min (SER_NO)+1 AS 'Desired total ',
count(*) - (max (SER_NO)- min (SER_NO)+1) AS 'Missing Records',
min (SER_NO) AS 'MIN SER_NO',
max (SER_NO) AS 'MAX SER_NO'
from Info_Table
where DateTime >= @date and DateTime < dateadd(DAY, 1, @date)
I would like to get records of next 30 days from the @date. I can copy
paste this query 30 times with different date and get the desired
results but would prefer to use one query only.
If possible would like a add a variable to get the table name by using
the following query into the above query:
SELECT DISTINCT so.name
FROM sysobjects AS so
INNER JOIN syscolumns AS sc
ON so.id=sc.id
WHERE so.name like 'm_%' AND sc.name = 'DateTime' OR sc.name ='SER_NO'
So basic idea is to run one simple (or complexed) query to get 30 days
data of many tables select by the above query.
Can someone help please?