I am working on a commercial website that is using ASP and an access database.
I have a pretty elaborate select statement that works, except for part of the ORDER clause.
Here is the scenario.... my client sells automotive parts...
Table 1: (itemsku) holds part numbers
Table 2: (itemveh) holds vehicles that work with those parts along with some descriptive clarification (cab size, bed size, years, ...)
Table 3: (make) holds the vehicles make name (ford, chevy, ...)
Table 4: (model) holds the vehicles model name (F150, Ram, Silverado...)
I need to get a list of parts and their approriate descriptions and sort it by Make, Model, Specific Description, and year.
((itemsku left join itemveh on itemsku.id=itemveh.itemsku_id)
left join model on itemveh.model_id = model.id)
left join make on model.make_id=make.id
where itemsku.item_id=4
order by
make.name,model.name,itemsku.desc_sku
If I put it as listed, all sorts properly, except for the years. As soon as I add to the end of the order by....
, itemsku.yr_beg desc
Then, the desc_sku portion does NOT sort properly, but the years do. I have tried dropping the desc as well to see if that would help, but the desc_sku does not play into the sort factor if the yr_beg is added.
Am I missing something or is their a limit as to the number of fields in an ORDER?
After some research I thought I had found a neat way to SELECT records from a table based on an 'IN' clause and sort them in the same order as the values for the 'IN' clause... i.e.
Code: SELECT Unique_No, Table_Name, List_Order FROM My_Table WHERE Table_Name = 'Titles' AND List_Order IN (3,1,15,4,5,12,7,2) ORDER BY INSTR('3,1,15,4,5,12,7,2', List_Order)
Unfortunately, this returns list_order 5 just after 15 and list_order 2 just after 12, thus
Basically, my database holds records of sites in the UK, and I have a select query (qry_SumGIS3) that opens up a summary report (rptSumGIS3) when a button is clicked on the menu page. The report opens perfectly, showing me all the information I need to know about all the sites in my database. However, it is ignoring the Order By Clause I have specifically told it to do. I want to order the records that appear in the report by a calculated field (OBJ_WS_OVERALL_CALC) in descending order (highest to lowest percentage). Instead, it is ordering it by the site id (RTP_ID). How can I stop it doing this?
This is my code (that was created in the SQL view of the query design): "SELECT MEASURE1.OBJ_WS_OVERALL_CALC, [Tab 1: Factual].RTP_ID, OBJECTIVES.OBJ_ID, OBJECTIVES.OBJ_NAME, MEASURE1.MEASURE_ID, MEASURE.MEASURE_NAME, MEASURE1.MEASURE_SCORE, MEASURE1.MEASURE_WEIGHT FROM [Tab 1: Factual] INNER JOIN (OBJECTIVES INNER JOIN (MEASURE1 INNER JOIN MEASURE ON MEASURE1.MEASURE_ID = MEASURE.MEASURE_ID) ON OBJECTIVES.OBJ_ID = MEASURE.OBJ_ID) ON [Tab 1: Factual].RTP_ID = MEASURE1.RTP_ID ORDER BY MEASURE1.OBJ_WS_OVERALL_CALC;"
The red line is the part of the code that I think is being ignored.
Can someone please tell me if it is possible to pass in a parameter for the sorting field to a stored procedure in MS Access. When I tried to execute a query similar to below, neither did the query give me an error nor did it execute correctly.
PARAMETERS ORDERBY_FIELD as Text; Select * from Employees Order By ORDERBY_FIELD;
It will be great if someone could help me with this.
From a performance perspective, does it matter in what order a number of clauses are specified ? For example if many records satisfy ConditionA but few records satisfy ConditionB, is it better to put ConditionB first ?
SELECT Fields FROM Table WHERE ConditionA and ConditionB or SELECT Fields FROM Table WHERE ConditionB and ConditionA
I have a Report that uses a query as it's record source. I have the query ordered by a field, which works as expected in the table view of the query. In the report, however, the ORDER BY clause does not seem to carry through. The field is not sorted Ascending. What's going on?
I've been trying to work up a where clause that is generated by a button click event on a report. The workflow that i'm trying to obtain is as follows:
1) A report is run to determine the remaining work orders that need to be processed. 2) A button that is placed on that report is to be clicked, taking the user to the form associated with that work order, so it can be processed.
What i've been able to do so far is capture the unique ID for the work order and then print that in a message box. I can then open the form.
What i haven't been able to accomplish thus far is to open the form to the correct work order.
Things I've tried : I started trying to use the macro with the search for record option and using the where clause. Not successful. I am a little more comfortable in using vba so i switched to that pretty quickly.
Code: Private Sub btnJobEntry_Click() 'GOAL: open the work order form to the correct entry 'METHOD: store the uniqueID to a variable, then use that in the open command's where clause Dim strJobID As String 'store the unique ID in the variable
[Code] ....
I've put the strJobID variable in both the filter and where clause sections of the DoCmd but it just opens the form to the first entry. I'm fairly confident i'm not applying the filter/where clause correctly by using the incorrect syntax.
I have the following SQL statement. The COUNT(b.BookingID) AS TB, gives me the number of bookings. I need to ensure that the number of bookings + PrebookCapacity is less than v.Capacity. I do this by:
COUNT(b.BookingID) AS TB + PrebookCapacity < v.Capacity in the WHERE CLAUSE. But when I run this in MS Access 2003, it says Enter Parameter Value for b.TB (It does not recognise b.TB as b.TB is not a table field). If I omit AND ((b.TB + PrebookCapacity < v.Capacity AND SessionStatus = 1) OR (b.TB < v.Capacity AND SessionStatus = 0)), from the WHERE clause, it works fine, also giving me the TB.
As I need to do my check in the WHERE clause, how can I check to make sure that the COUNT(b.BookingID) AS TB + PrebookCapacity is < v.Capacity, without any problems.
SELECT CourseName, Format([s.SessionDate]+[s.StartTime],"dd/mmm/yyyy hh:ss AM/PM") & " - " & Format([s.EndTime],"hh:ss AM/PM") AS [DateTime], s.SessionID, PrebookCapacity, v.Capacity, COUNT(b.BookingID) AS TB FROM tblCourses AS c, tblSessions AS s, tblVenues AS v, tblbookings AS b, qrySessionsAccepted AS q WHERE c.CourseID = s.CourseID AND s.SessionID = 85 AND q.SessionID = s.SessionID AND b.SessionID = s.SessionID AND v.VenueID = s.VenueID AND ((b.TB + PrebookCapacity < v.Capacity AND SessionStatus = 1) OR (b.TB < v.Capacity AND SessionStatus = 0)) GROUP BY CourseName, Format([s.SessionDate]+[s.StartTime],"dd/mmm/yyyy hh:ss AM/PM") & " - " & Format([s.EndTime],"hh:ss AM/PM"), s.SessionID, PrebookCapacity, v.Capacity;
I now want another query which returns the row which is always the latest STATUSDATE. This is what I have done so far:
SELECT qryFirst.PROBLEM_ID, Last(qryFirst.STATUS_ID) AS LAST_STATUS FROM qryFirst GROUP BY qryFirst.PROBLEM_ID;
However, when I want to add qryFirst.STATUSDATE to the SELECT clause, I get an error „You tried to execute a query that does not include the specified expression <name> as part of an aggregate function. (Error 3122)“
I need to see what the STATUSDATE is for each of the records returned in the second query. How do I do this? Please!!!!
I need to extract the date from CODEDATE field if the "-" character exist in or from DATE1 if the character "-" is not present in the CODEDATE field, then filter the query on the date found.
I wrote that:
Code: SELECT IIf(Mid([CODEDATE],3,1)='-',Mid([CODEDATE],4,10),[DATE1]) AS DateFound FROM MyTable WHERE (IIf(Mid([CODEDATE],3,1)='-',Mid([CODEDATE],4,10),[DATE1]) Between 1/1/2013 And 31/12/2013)
The query above extra extract some records without sense for me, I tried many other syntax without success.
I re-arranged things in the code to try to make it clear as to whats going on. But I'm at a loss to why the qry will only run once. When I open the db and add a new record it works, when I try to add the next one, it doesnt....
Is this an issue with Access or is it me? I stripped it down in case someone could look at it....
The a mousehook module in the db to prevent scrolling..
I have a client table. I have a client product table for ski's Each Client has 1 or more products (skis)
I have a Service Order table and form that I use a drop down control in the Service order to select the customer.In the Service Order Form a I have a continuous Subform for detailed service.
This is where I'm having the problem.In the detail subform I want to select from a drop down box the customers particular ski that I want to service. how to have only that one customers ski's to show up.
and i needed a return (WHERE clause) when job_id is the same (i.e 2), and the crew_id is repeated like 4,4 and 33, how would i write it. I am trying to only sum the rows when this condition is fulfilled. Can anyoen help me
Could anyone explain me the following sysntax : ... where ((cond1 and cond2) and (fld1<>'54')<>'60') the syntax did not return any error while executing the query.
I have an select statment that pulls data from a server. This server is really slow, and there is quite a bit of data. This statement has the following where clause.
"WHERE upc_number = '" & strPikWhere & "' AND ((dbo_root_description_type.description_name)='PFM S' Or " & _
"(dbo_root_description_type.description_name)='Full tech') AND ((dbo_root_price.zone) Not Like '8*') " & _
I was wondering if the order of these where statements would make a difference, and if so how?
I have a query using the between clause with dates #01/01/2006# and #01/01/2007#. I have been reading a little on the between clause and it differs from SQL program to SQL program. What are its characteristics in MS Access is it >=#01/01/2006# AND <=#01/01/2007# or >=#01/01/2006# AND <#01/01/2007#.
When I do a Debug Print for where I get cardnumber = 1111111 The card number is a string because it might have a letter in it don't i need it to be cardnumber = "1111111"
I have a table "addresses" that has the following fields....... id - type - street1 - street2
and type can be one of the follwoing graduation,home,work
I am trying to write a query that gives the graduation address if it exists or if graduation doesnt exist it gives the home address..... I was thinking of an If clause but do not know how to do it.... can i write a module...??? Any help on this is appreciated..... Any other method also can be suggested....
In one of my queries, I'd like to reuse a calculated field as criteria in the Where clause. SQL seems reluctant to want to do this. You can RESTATE the calculation in the Where clause, but can't refer to it by Name. You can Order by it, but it can't be in the Where clause.
If the query result set consists on a set of Named columns, why can you refer to a calculated column by Name in the "Order By" clause but not in the Where clause?
Why is this OK?
Select FldA As FirstField, FldB As SecondField, FldA - FldB As TheDifference <-- Just a calculated field From SomeTable
And this is OK?
Select FldA As FirstField, FldB As SecondField, FldA - FldB As TheDifference From SomeTable Order By TheDifference <-- Order By is OK
And this in not OK?
Select FldA As FirstField, FldB As SecondField, FldA - FldB As TheDifference From SomeTable Where TheDifference > 100 <-- Can't use TheDifference in Where clause
Don't want to repeat the calculation.
Select FldA As FirstField, FldB As SecondField, FldA - FldB As TheDifference From SomeTable Where FldA - FldB > 100 <-- I know this works, but ... Order By TheDifference
hi, is it possible to have a form where you enter a word in a text box and it searchs a table and brings up all records which match it, but it doesnt have to be an exact match.
When I try to open the recordset with this, it says there is an error in the WHERE clause. I've tried changing all sorts of things but nothing works. I've tried with the WHERE clause commented out and it all works fine then.
Hi I'm new to query writing and I'm needing help with a query that will search a field that either contains a name or an address and only return fields with addresses.
Select address1 From Booktable, Where (Left([address1],1) = Like "[A-Z]"
SELECT Field1, Field2 from table1 where table1.Field2 in (1,2,3)
and now i need to parameterize this query.... I tried with
SELECT Field1, Field2 from table1 where table1.Field2 in ([Parameter])
Now the problem is... it is working fine with only one value For example if I input 1, it provide the required result. however, if I input 1,2 it doesnt provide a single recordset
I changed the datatype of parameter from number to text and also tried different way of inputting number like "1,2" , 1,2, but still problem is the same...
Can someone please guide me where I am going wrong
This probably sounds stupid but I need to ask because well, I'm stupid. I have created a separate table of partnumbers that DO NOT get included in a SELECT Query for another table (tblmain). How can I use this table in my WHERE clause? Below is my SQL statement and the table with the partnumbers is tblreportpartnumbers.
strSQL = "SELECT SUM([Yield]) AS [My Sum] FROM tblmain" strSQL = strSQL & " WHERE(([Area]='Cell 1 Supfina' AND " strSQL = strSQL & "([Date entered]=#" & dtmdate & "#" strSQL = strSQL & " AND([Part Number]=???????)))" strSQL = strSQL & " Group By [Date entered];"