usallc@gmail.com (sah) wrote in message news:<3624d871.0409230744.5b13e42e@posting.google. com>...[color=blue]
> 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?[/color]
That worked, thanks.
Now to the second part of it. Please review the following 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'
I wrote this query to get table names using certain filters. How can I
use this in the previous query instad of the table name.
Also a minor thing. The query you helped me with gives records for one
months only, can you please guide me in getting records from greater
then the given date.
Thanks.