2011-05-05 123 views
0

我需要數匹配在GID的查詢兩個表

Dim iSubscriptionCount 

SQLCommand = "SELECT COUNT(*) AS Counter FROM Directories.GID, ClientSubscriptons.DirectoryGID FROM Directories, ClientSubscriptons WHERE Directories.GID = ClientSubscriptons.DirectoryGID;" 
      rsTemp.Open SQLCommand, objConn, adOpenStatic, adLockReadOnly 
      iSubscriptionCount = rsTemp("Counter") 
      rsTemp.Close 
      if iSubscriptionCount <= 0 then 
          %><a href="AddDirectory.asp?PGID=<% = rsDirectory("GID") %>"><% = GetIcon("Add", "Add Sub Directory", 25, True) %></a><%   

將記錄數我需要計算的匹配在GID的

回答

0

你的問題不是很清楚......如果你只是想算你必須執行JOIN這樣

SELECT COUNT(*) AS Counter FROM 
Directories join ClientSubscriptons 
on Directories.GID = ClientSubscriptons.DirectoryGID 

的特許經營部分是完全隱藏目錄和客戶端訂閱之間的比賽.. 。你要同時匹配表上franchiseGID?如果您的查詢應該是這樣的

SELECT COUNT(*) AS Counter FROM 
Directories join ClientSubscriptons 
on Directories.GID = ClientSubscriptons.DirectoryGID 
and Directories.FranchiseGID = ClientSubscriptons.FranchiseGID 

對於你需要更加清晰,請

+0

不客氣 – 2011-05-05 16:01:47

0

的記錄數你有2個從條款.. 。 SQL後應當讀...

SELECT COUNT(*) AS Counter, Directories.GID, ClientSubscriptions.DirectoryGID 
    FROM Directories, ClientSubscriptions 
    WHERE Directories.GID = ClientSubscriptions.DirectoryGID 

您可能還需要一個

GROUP BY Directories.GID, ClientSubscriptions.DirectoryGID; 

最後

+0

的Clie更準確的答案ntSubscriptons拼寫錯誤。這可能是問題。 – IAmTimCorey 2011-05-05 15:34:10

0

我不太瞭解Visual Basic嗎?但是你在同一個句子中有兩個'FROM'。不會

SELECT COUNT(*) AS Counter 
FROM Directories, ClientSubscriptons 
WHERE Directories.GID = ClientSubscriptons.DirectoryGID 

解決問題?