Why am I getting an error for specified expression in a Query? - ms-access-2013

I keep getting the following error:
Your query does not include the specified expression '[Employees}.{Last Name] & "," & [First Name]' as part of an aggregate function.
This is the SQL View:
SELECT [Employees].[Last Name] & ", " & [First Name] AS EmployeeName,
Sum(IIf([Vacation Calendar].[TypeID]=1,[Vacation Calendar].[Time],0)) AS SumOfSickTime
FROM Employees
INNER
JOIN [Vacation Calendar]
ON Employees.ID = [Vacation Calendar].EmployeeID
WHERE (((Employees.[Active Employee])=True))
ORDER
BY [Employees].[Last Name] & ", " & [First Name];

you are using SUM so you need to include a GROUP BY function at the end of your query.
Something like GROUP BY [Employees].[Last Name] & ", " & [First Name]
using ORDER BY wont fix this

Related

Problem with google docs query and importrange

I'm trying to import any row from the URL where column 1 contains the string 6293. When I execute this query all I get is the first row from the URL which does not contain the string 6293. BTW if I change the "where 1" clause to "where col1" I get an error. What am I doing wrong?
=query(importrange("URL","Cost Per SKU!a1:q1000"),"select * where 1 = '6293'")
try:
=QUERY(IMPORTRANGE("URL", "Cost Per SKU!A1:Q1000"),
"where Col1 = '6293'")
or:
=QUERY(IMPORTRANGE("URL", "Cost Per SKU!A1:Q1000"),
"where Col1 = 6293")

Syntax error (missing operator) in query expression on vb6

I have been searching for an answer on Stack Overflow and on Google but found nothing. I am doing this as a school project and can not get my head around it.
I'm am working with a Access Database and it will not allow me to search for the last name.
Here is my problem: Syntax error (missing operator) in query expression 'Last Name = '(Namethatwastypedwithoutbrackets)"
And this is my code
Private Sub cmdSearch_Click()
Dim sql As String
Call Conn.Connect
Adodc1.ConnectionString = Conn.connstr
Adodc1.CommandType = adCmdText
Adodc1.ConnectionString = connstr
sql = "Select * from Table1 where Last Name = '" & txtSearch.Text & "'"
Adodc1.RecordSource = sql
Adodc1.Refresh
End Sub
I really appreciate if anyone can tell me what's wrong since i don't have any idea what the error is.
The error message is telling you that you need brackets around your column name (Last Name) because it has spaces in it.
sql = "Select * from Table1 where [Last Name] = '" & txtSearch.Text & "'"

How to perform left join in hql to fetch data

I am using following query to get data data database
String hql = "from Parameters s "
+"left join fetch s.userValues as uv "
+ "where s.groupId=:gid "
+"and uv.user.id=:uid " ;
Above is my hql query here I am fetching data from Parameter and from userValues.
This query is working properly if user have any value in userValues.
This query is not fetching any value when there is no saved value for user in userValues.
My problem is Whether there should be data in userValues or not I want to fetch data from Parameters.
How to achieve this using hql?
I just want to do left join in hql to get first table values.
You probably want something like this. You need to left join the association to user also. Note that you should use the Hibernate mapping between Parameter and Group as below. But you will probably need to use grouping to remove duplicate results.
String hql = "from Parameters s "
+ "join s.group g "
+ "left join fetch s.userValues uv "
+ "left join uv.user u "
+ "where g.id=:gid "
+ "and (u.id=:uid or u is null) ";

how to make a report act like a bill

i have a form it's purpose to view a client (client table) and a number of orders (order table)
i need when the user build the order to a client the user can press a button called print bill so the report shows out and the name of client appear in the head section from the client table, and the order in the body section(it could be a 100 item ordered), and the total discount in the footer section
i know the query "Select * from order where id = '"& Txtid.Text &"'"
but i cant do it, it only require a pure sql command without Txtid.Text
So how to include the Txtid.text within the query?
how can i send a whatever query and the result came out in a report, i only can make a command and build a report on it, so it must be a way to change the command from the code so the report view the data dynamiclly
Probably you need to select multiple items.
Try adding a ListBox to your form with multiple selection enabled. You could then concatenate all of your IDs from the ListBox into a string and use the IN comparator for your criteria, like so:
sqlString =
"SELECT " & _
"field1, " & _
"field2, " & _
"fieldn " & _
"FROM " & _
"order " & _
"WHERE " & _
"ID IN (" & concatListIds & ") "

Bind parameters for ORDER BY in NamedParameterJDBCTemplate

I am trying to use NamedParameterJdbTemplate in a Spring MVC application. The issue is that the bind parameters do not seem to work (no sorting happens) when I include one of ORDER BY clauses listed below. However, a hard coded order by column name in the sql works.
ORDER BY column1
ORDER BY column1
ORDER BY column1 asc
ORDER BY column1 desc
For example, the below listed query does not work.
private static final String SEARCH_ALL_BY_SORT_ORDER=
" select FIRST_NM, MIDDLE_NM, LAST_NM, CUSTOMER_IDENTIFIER, EMAIL_ADDRESS, ACCOUNT_ID" +
" from VIEW " +
" where CUSTOMER_IDENTIFIER= :customerIdentifier " +
" and ( REGEXP_LIKE(FIRST_NM, :firstName, 'i') " +
" or REGEXP_LIKE(LAST_NM, :lastName, 'i') " +
" or REGEXP_LIKE(EMAIL_ADDRESS, :emailAddress, 'i') )" +
" order by :sortColumns";
The same query with a hard coded order by column works:
private static final String SEARCH_ALL_BY_SORT_ORDER=
" select FIRST_NM, MIDDLE_NM, LAST_NM, CUSTOMER_IDENTIFIER, EMAIL_ADDRESS, ACCOUNT_ID" +
" from VIEW " +
" where CUSTOMER_IDENTIFIER= :customerIdentifier " +
" and ( REGEXP_LIKE(FIRST_NM, :firstName, 'i') " +
" or REGEXP_LIKE(LAST_NM, :lastName, 'i') " +
" or REGEXP_LIKE(EMAIL_ADDRESS, :emailAddress, 'i') )" +
" order by LAST_NM";
Here's the relevant jdbctemplate code
Map <String, Object> params = new HashMap <String, Object>();
params.put("customerIdentifier", customerIdentifier);
params.put("firstName", searchCriteria );
params.put("lastName", searchCriteria );
params.put("emailAddress",searchCriteria);
// sortBy is COLUMN name
// sortOrder is either 'asc' or 'desc'
params.put("sortColumns", sortBy + " " + sortOrder);
// Using just the column name does not work either
//params.put("sortColumns", sortBy);
namedParameterJdbcTemplate.query(SEARCH_ALL_BY_SORT_ORDER, params, new MemberMapper());
Only values can be bound as parameters. Not parts of the query itself.
In the end, a prepared statement is generated and the parameters are bound to the prepared statement. The principle of a prepared statement is to prepare the execution plan of the query (of which the order by clause is a part), and to execute the query one or several times after, with varying parameters.
If the query is not complete, the execution plan can't be prepared and reused. So, for this part of the query, you'll need to generate the query dynamically using string concatenation, and not parameters.
As JB Nizet has already explained that parts of query cannot be used as bind keys (orderby :age). Therefore we will need to use concatenation here instead.
" order by "+ sortBy + " " + sortOrder;

Resources