473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

building an sql query with javascript and ASP

347 100+
I am trying to build a sql query for an exam site and need to list the top scoring exams for a user, there can be multiple exams.

I have the following script in ASP that puts the results into a javascript function so they can be read by a cms system on another server.

Expand|Select|Wrap|Line Numbers
  1. rs.Source = "select ID, Username, UserID, Test_Name, MAX(Grade) FROM testscores WHERE UserID = " & Session("sesUserID") & " AND Grade > 69 GROUP BY UserID,Test_Name ORDER BY CAST(Grade AS UNSIGNED)"
  2.  
  3.  
  4. Response.write("moduleCertificates: function(){")
  5. response.write(vbcrlf)
  6. response.write ("return {")
  7.  
  8. rs.Open()    
  9. while not rs.eof
  10.  
  11. Dim testName_Short
  12. Dim testName
  13.  
  14. testName = rs.Fields.Item("test_Name").Value
  15. testName_Short = testName
  16. testName_Short = replace(testName_Short, "Gold_", "")
  17. testName_Short = replace(testName_Short, "Silver_", "")
  18. testName_Short = replace(testName_Short, "Bronze_", "")    
  19.  
  20. response.write("'" & testName_Short & "': ' https://testwww.sharpacademy.eu/certificate.swf?UID=" & rs.Fields.Item("UserID").Value &"&ID=" & rs.Fields.Item("ID").Value & "',")
  21. response.write(vbcrlf)
  22.  
  23. rs.MoveNext
  24. Wend
  25. response.write ("};")
  26. response.write(vbcrlf)
  27. response.write ("}")
  28. response.write(vbcrlf)
  29. rs.Close
  30. Set rs = Nothing
  31.  
this returns one result per exam for the user but it is the first one in the database for the exam and user.

i only need to return the ID and UserID from the database.

Any help would be appreciated
Jul 16 '14 #1
3 1353
Rabbit
12,516 Expert Mod 8TB
You're saying that query runs? I don't see how that's possible, there are syntax errors. You have fields in your SELECT that aren't in your GROUP BY or in an AGGREGATE function.
Jul 16 '14 #2
colinod
347 100+
as far as i am aware i can group by 1 field, why would you want to group by multiple fields
Jul 18 '14 #3
Rabbit
12,516 Expert Mod 8TB
You can group by 1 field if you use the rest of the fields in an aggregate function.

You would want to group by multiple fields if those fields represent the unique combination that you want to aggregate by.

When you do an aggregate query, every field in the SELECT has to be either in a group by or in an aggregate function. Otherwise, the database has no idea what value to select for the rest of the fields.
Jul 18 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jim Heavey | last post by:
Hello, I was wondering how I would go about attaching some Java script code to a <asp:EditCommandColumn. If the user presses the "edit" link, then I want to test other controls to see if any...
1
by: dhruba.bandopadhyay | last post by:
Is it possible for JavaScript to access the DOM of ASP.NET Web/Server Controls? For example, I have a legacy HTML forms, controls, etc. If I convert all my HTML into Web Controls (by adding...
3
by: visionstate | last post by:
Hi All, I have used the following article to help me build a query 'on the fly': http://www.fontstuff.com/access/acctut17.htm It's a very useful article and is exactly what I was looking for to...
2
by: Rabel | last post by:
Hi I am a novice with both asp and javascript so I may not even be doing this correctly, but I have an asp page that has variable being passed to it and I have a button that I need to have it go to...
1
by: Twanne | last post by:
I've got this query Set rst4 = db.OpenRecordset("SELECT L,M,S FROM referenties WHERE type = '" & Form_PatChoise.ctype & "' AND geslacht = '" & Form_PatChoise.Sex & "' AND leeftijd = '" &...
2
by: StevoNZ | last post by:
Hi, I'm creating a query (queries more like) to build data for upload into a SAP system. For a given material I require a row of data defined, and for the same material another row with one field...
1
by: cdhaynes | last post by:
Hi, I am using unbound text boxes in the header of a form to allow the user to search on a number of fields. I am using VBA to build a query string based on these and it has been fine when comparing...
1
by: rush2hem | last post by:
I am trying to build a query which will give me unique rows. Details:- Table 1 (F1, F2 are the columns) F1 F2 1 A1 2 A2 3 A3 4 A4 Table 2 (F3,F4 are the columns) F3 F4
11
by: kadishzm | last post by:
Hi Everyone, I have recently been tasked with taking over a bunch of Access databases that I didn't create. My VBA skills are weak to say the best but I have a particular problem I am working on....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.