GROUP_CONCAT() error in h2 [42001-214] , [42122-214] - sql

i keep getting this error GROUP_CONCAT(""""[*],a.montant, a.type_avance,a.date_avance,
a.remark SEPARATOR '') as Avance [42001-214] ,and after
i removed GROUP_CONCAT to test the code i got the error:
Column "" not found; SQL statement [42122-214]
here is my code:
SELECT i.n_dossier , concat(\"<html>\",i.nom_prenom,\"<br></html>\")
,concat(\"<html>\",i.vehicule,\"<br></html>\"),i.prime_totale ,"
+ " i.date_effet , i.date_echean ,GROUP_CONCAT(\"<html>\",a.montant,"
+ " a.type_avance,a.date_avance,a.remark SEPARATOR \"<br>\") as Avance ,i.reste ,i.GSM,"
+ "i.observation ,\"</html>\" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = "
+ " a.n_dossier GROUP by i.n_dossier,i.date_dossier,i.anuller having i.anuller = ' active '

You must repalce
GROUP_CONCAT("<html>",a.montant, a.type_avance,a.date_avance,a.remark SEPARATOR "<br>")
with
GROUP_CONCAT(CONCAT("<html>",a.montant, a.type_avance,a.date_avance,a.remark) SEPARATOR "<br>")
GROUP_CONCAT needs to have 1 column, as you see in the samle CONCAT will do that.
I don't why you use single quorted ' active 'and doou

Related

HQL unexpected token "(" subquery select

I have this query. Translate it from my sql query to hql. I have this error
"unexpected token: ( near line 2, column"
String query = "SELECT MAX(number)\n" +
" FROM (SELECT number FROM EmployeeTripCard \n" +
" WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" +
" UNION ALL\n" +
" SELECT trip_card_number FROM PostgraduateTripCard\n" +
" WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" +
" UNION ALL\n" +
" SELECT trip_card_number FROM StudentTripCard \n" +
" WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" +
" )";
Integer result = (Integer) getSessionFactory().getCurrentSession().createQuery(query).uniqueResult();
I don't underastand what'w wrong
My bad Vytsalo, didnt look at the databse tag.
HQL subqueries is not supported on from clauses
Note that HQL subqueries can occur only in the select or where clauses:Hibernate Query Language

token expression in flat file connection

I have loaded the variables in the format for example:
where produkt = 'Muj zivot2 R' and uraz = 'Uraz'
and I need the output in the file name to be:
Muj zivot2 R_Uraz
token worked for me, but it doesn't work in this case
" + TOKEN(" #[User::where] ","''",2) + "_" + TOKEN(" #[User::where] ","''",4) + "
You can use the following expression:
TOKEN(#[User::where],"'",2) + "_" + TOKEN(#[User::where],"'",4)
Output
Muj zivot2 R_Uraz

Web2Py insert into database error

I am trying to make insert. This is my code:
db.define_table('orders',
Field('idProduct', type = 'integer'),
Field('quantity', type = 'integer'),
Field('idUser', type = 'integer'),
Field('status'),
Field('order_date'),
Field('product_price', type = 'integer'))
The SQL:
sql = "Insert into orders (idProduct,idUser,quantity,status,order_date,product_price) values "
sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," + str(quantity) + ",'cart','" + str(order_date)+ "," + str(product_price)+"')"
and I am getting following error:
<class 'sqlite3.OperationalError'> 5 values for 6 columns
I don't understand what is wrong, because if i remove product_price, everything is working.
Thanks.
You have extra quote before the last closing bracket. Remove it and it will fix the error:
sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," +
str(quantity) + ",'cart','" + str(order_date)+ "," +
str(product_price)+")"

Pass a SQL condition as a OleDb parameter

I have following code:
Dim executedCmd As OleDb.OleDbCommand = m_dbMgr.GetCommand()
executedCmd.CommandText = "select * from [Parameters] where "
Dim SQLcondition As String = String.Empty
For i As Integer = 0 To ParameterName.Count - 1
executedCmd.CommandText += "ParameterName = #parametername" + i.ToString() + " and ParameterValue #ParamaterCondition" + i.ToString() + " #ParameterValue" + i.ToString()
executedCmd.Parameters.AddWithValue("#parametername" + i.ToString(), ParameterName(i))
executedCmd.Parameters.AddWithValue("#ParameterValue" + i.ToString(), ParameterValue(i))
executedCmd.Parameters.AddWithValue("#ParamaterCondition" + i.ToString(), Condition(i))
Next
ParameterName, ParameterValue, ParameterCondition all are same length ArrayList, but the code does not work properly. I have verified all the variables have values.
When I run the code it reports a syntax error: "missing operations in query expression"
The problem is that ParameterCondition has values like ('>', '<', '=',.... some logical SQL operators).
Edit: How can I include conditions in parameters?
Add 1 = 1 after where to simplify building logical expression. Notice that all conditions added by AND logical operator. You can generate parameter name from columns name.
executedCmd.CommandText = "select * from [Parameters] where 1 = 1"
....
executedCmd.CommandText += " AND " + ParameterName(i) + " " + Condition(i) + " #" + ParameterName(i)
executedCmd.Parameters.AddWithValue("#" + ParameterName(i), ParameterValue(i))
ParameterCondition must all be binary operators.
The database engine would check the syntax of the SQL statement before it replaces the parameters with values. So somethinhg like "WHERE #p1 #p2 #p3" will not be parsed correctly.
Replace your condition with a string-expression e.g.
commandtext = parameterName + condition + " #p1"

SQL incorrect syntax near a table name after FROM and before INNER JOIN.

Hi I have this SELECT query. I've tried excuting the query on the SQL Pane on Visual Studio 2008 and it works. However when I run the page (this is an asp.net page), it throws an SQL Exception saying I have an incorrect syntax near Schedules.
string selectSchedString = "SELECT Subjects.subject_title, Schedules.class_day, CAST(MIN(Schedules.time_in) AS varchar(10)) + ' - ' + CAST(MAX(Schedules.time_out) AS varchar(10)) AS Expr1" +
"FROM Schedules "+ //The exception points here
"INNER JOIN Subjects ON Schedules.subject_id = Subjects.subject_id " +
"INNER JOIN Student ON Student.section_id = " + currentSection + " " +
"GROUP BY Subjects.subject_title, Schedules.class_day";
Any ideas? As I've said, I tried excuting this on the SQL pane and it worked. Is there any special condition in asp.net that I've missed or something?
You are missing any white space between the end of the first line and FROM
Change AS Expr1" to AS Expr1 "
This is because the concatinated string is not correct try:
string selectSchedString = "SELECT Subjects.subject_title, Schedules.class_day, CAST(MIN(Schedules.time_in) AS varchar(10)) + ' - ' + CAST(MAX(Schedules.time_out) AS varchar(10)) AS Expr1" +
" FROM Schedules "+ //The exception points here
" INNER JOIN Subjects ON Schedules.subject_id = Subjects.subject_id " +
" INNER JOIN Student ON Student.section_id = " + currentSection + " " +
" GROUP BY Subjects.subject_title, Schedules.class_day";
Notice the empty spaces.