all groups > sql server programming > july 2005 >
You're in the

sql server programming

group:

Counting Records


Counting Records WhiteJul
7/13/2005 10:35:15 PM
sql server programming:
I have a table (transactionsTable) and I have several records from July 1st
till today that I would like to count
I prepared the following SQL statement but it does not work, please advise.
Thanks

Select count (*)
from TransactionsTable
where [date] = '2005/07/01' and '2005/07/14'

Re: Counting Records WhiteJul
7/13/2005 10:52:41 PM
Hari: it worked, now I have the same table in three separated SQL servers,
how can Iquery the three servers with only one query to see and compare
their respective counts.

I tried:

Select count (*) from sqlServerONE.dbo.TransactionsTable
where [date] between '2005/07/01' and '2005/07/14'

Select count (*) from sqlServerTWO.dbo.TransactionsTable
where [date] between '2005/07/01' and '2005/07/14'

Select count (*) from sqlServerTHREE.dbo.TransactionsTable
where [date] between '2005/07/01' and '2005/07/14'

The three servers have the same password for the SA account.

Thanks for any assistance!

[quoted text, click to view]

Re: Counting Records Hari Prasad
7/14/2005 12:00:00 AM
Hi,

Use Between clause

Select count (*) from TransactionsTable where [date] between '2005/07/01'
and '2005/07/14'

Thanks
Hari
SQL Server MVP

[quoted text, click to view]

Re: Counting Records John Bell
7/14/2005 12:41:02 AM
Hi

I assume that you have created linked servers to do this? You will need four
part names to do this. if you are running this on server 1 then

Select count (*) AS [Number]. 'Server One' AS [Server]
from dbo.TransactionsTable
where [date] between '2005/07/01' and '2005/07/14'
UNION ALL
Select count (*), 'Server Two'
from sqlServerTWO.db2..TransactionsTable
where [date] between '2005/07/01' and '2005/07/14'
UNION ALL
Select count (*), 'Server Three'
from sqlServerTHREE.db3..TransactionsTable
where [date] between '2005/07/01' and '2005/07/14'

John
[quoted text, click to view]
Re: Counting Records WhiteJul
7/14/2005 9:16:05 AM
No, I do not have linked servers, how can accomplish this?
I also tried to run this query and got the error message below. Thanks for
any help:

Select count (*) AS [Number]. 'SqlServerOne' AS [Server]
from dbo.TransactionsTable
where [date] between '2005/07/10' and '2005/07/14'
UNION ALL
Select count (*), 'SqlServerTwo'
from SqlServerTwo.dbo..TransactionsTable
where [date] between '2005/07/10' and '2005/07/14'
UNION ALL
Select count (*), 'SqlServerThree'
from SqlServerThree.dbo..TransactionsTable
where [date] between '2005/07/10' and '2005/07/14'

Error:
====
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '.'.

[quoted text, click to view]
Re: Counting Records John Bell
7/14/2005 10:25:12 AM
Hi

There is a full-stop instead of a comma after [Number].

To set one up follow the instructions in the topic "How to set up a linked
server (Enterprise Manager)" or if you want to use T-SQL and Query Analyser
check out
the topic "Adding a Linked Server" and "sp_addlinkedserver" also look at
"Establishing Security for Linked Servers". All of these topics are in Books
Online.


John

[quoted text, click to view]
Re: Counting Records WhiteJul
7/14/2005 9:47:23 PM
I did work. I changed the period (.) by a comma and it run fine.
I also managed to created the linked servers.
Thanks John.

[quoted text, click to view]

AddThis Social Bookmark Button