Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL Problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL Problem

 Post Reply Post Reply
Author
Pegaso View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 13 February 2003
Location: Switzerland
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Pegaso Quote  Post ReplyReply Direct Link To This Post Topic: SQL Problem
    Posted: 25 April 2003 at 1:21am

The following didn't work. Why??

strSQL = "SELECT tblNewsRating.News_ID, Avg(tblNewsRating.Rating) AS MediadiRating "
strSQL = strSQL & "FROM tblNewsRating "
strSQL = strSQL & "GROUP BY tblNewsRating.News_ID "
strSQL = strSQL & "WHERE tblNewsRating.News_ID = " & rsnews("News_ID") &";"

That's the error message:

Tipo di errore:
Microsoft JET Database Engine (0x80040E14)
Errore di sintassi (operatore mancante) nell'espressione della query 'tblNewsRating.News_ID WHERE tblNewsRating.News_ID = 117'.
/Ticinorally/testing2.asp, line 52

thanks to all for the help

 



Edited by Pegaso
Back to Top
Pegaso View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 13 February 2003
Location: Switzerland
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Pegaso Quote  Post ReplyReply Direct Link To This Post Posted: 25 April 2003 at 1:28am

Sorry I have found now the solution. And for all that have the same problem, here you have the solution:

strSQL = "SELECT tblNewsRating.News_ID, Avg(tblNewsRating.Rating) AS MediadiRating "
strSQL = strSQL & "FROM tblNewsRating "
strSQL = strSQL & "GROUP BY tblNewsRating.News_ID "
strSQL = strSQL & "HAVING tblNewsRating.News_ID = " & rsnews("News_ID") &";"

If you work with a Group you must use Having and not Where.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 25 April 2003 at 11:17am

actually thats not true, you can have

SELECT.. FROM .. WHERE... GROUP

"having" isn't absolutely required

Contribute to the working anarchy we fondly call the Internet
Back to Top
Pegaso View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 13 February 2003
Location: Switzerland
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Pegaso Quote  Post ReplyReply Direct Link To This Post Posted: 02 May 2003 at 8:28am
OK but with the WHERE command the SQL didn't work and with HAVING it works. Why?
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 02 May 2003 at 8:33am

notice i didnt say: replace "HAVING" with "WHERE"

there's more than one way to skin a cat

 

Contribute to the working anarchy we fondly call the Internet
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.