SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 9th, 2004, 01:23 AM
Traxx Traxx is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 Traxx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry sql statement is not working...

Hello,

I´m trying to create an sql statement with an inner join. Can anybody tell me, why this won´t works?
The variables date_from and date_to are defined.
Perhaps it´s a syntax probem?

sql = "SELECT table2.name, COUNT(table1.category_id) AS Anzahl FROM table1 WHERE OPENTIME BETWEEN '" & date_from & "' AND '" & date_to & "' AND t_call2.QUEUE_ID = '111' INNER JOIN table2 ON table1.category_id = table2.id GROUP BY table1.category_id, table2.name ORDER BY Anzahl DESC"

Thanks!

Reply With Quote
  #2  
Old August 10th, 2004, 11:19 AM
MJoTaM MJoTaM is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: UK
Posts: 131 MJoTaM User rank is Private First Class (20 - 50 Reputation Level)MJoTaM User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 12 h 33 m 37 sec
Reputation Power: 5
Hi there.

I think you have a couple of errors.
First of all you use fields in the query that you never select, then you use the WHERE statment before the INNER JOIN.
It is a bit messy to understand your SQL statment and a bit difficult to give an exact answer but try this.

Code:
SELECT COUNT(table1.category_id) As Anzah1, table2.name, table2.id, OPENTIME, t_call2.QUEUE_ID
FROM table1
INNER JOIN table2 ON table1.category_id = table2.id
WHERE OPENTIME BETWEEN '" & FormatDateTime ('date_from', vblongdate) & "' AND '" & FormatDateTime ('date_to', vblongdate) & "' AND t_call2.QUEUE_ID = '111'
GROUP BY table2.name , table2.id
ORDER BY COUNT(table1.category_id)DESC


Dont think it will work but give it a go.

Reply With Quote
  #3  
Old August 10th, 2004, 01:32 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
FormatDateTime isn't a valid SQL Function.
It appears you are trying to combine SQL with VBScript, which won't work.
Code:
strSql = "SELECT Table2.Name, COUNT(Table1.Category_ID) As Anzahl
FROM Table1 
INNER JOIN Table2 On (Table1.CategoryID = Table2.ID)
WHERE OpenTime BETWEEN '" & date_From & "' AND '" & date_to & "'
AND t_call2.QueueID = '111'<--- Where is this coming from? You aren't joining on a t_call2 table?
GROUP BY Table1.CategoryID, Table2.Name
ORDER BY Anzahl DESC"

You would have to use the VBScript FormatDateTime function to format the dates before you pass them to the sql statement.

Reply With Quote
  #4  
Old August 11th, 2004, 04:14 AM
MJoTaM MJoTaM is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: UK
Posts: 131 MJoTaM User rank is Private First Class (20 - 50 Reputation Level)MJoTaM User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 12 h 33 m 37 sec
Reputation Power: 5
You are correct Memnoch.
About this t_call2.QueueID, i dont know as well where to join, it just appears in original Traxx query.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > sql statement is not working...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT