using (SqlCommand cmd = new SqlCommand(
"select TaskTimeIn, TaskTimeOut, TaskDescription
from DailyTimeSheetTrackers
where EmployeeId = "+UserLog.UserId+" and CreateDateTime = " + DateTime.Now + ""
)
)
Error:
Incorrect syntax near '10'.
I got error like this.
How to solve it? Please help me
Related
I'm getting SQL exception while executing the query which contains
split_part() method as split_part(value::TEXT,':', 1).
String queryStr = " select split_part(value::TEXT,':', 1) from table";
Query query = entityManager.createNativeQuery(queryStr);
List results = query.getResultList();
ERROR 2020-02-10 14:54:37,926 [http-nio-7070-exec-1] 142 - ERROR: syntax error at or near ":"
Position: 855
Your obfuscation layer probably chokes on the :: operator. Use the cast() operator instead:
String queryStr = " select split_part(cast(value as text),':', 1) from table";
But why do you think you need the cast to begin with? If you are storing : characters that column, it is most probably a text (or varchar) column anyway and you don't need a cast at all.
i am working on a certain project. I have a JPA query, which i want to give me a result set but the result has to exclude entries matching some data in another table thus am using NOT IN. My query is as below:
String sql = "SELECT DISTINCT(tia.voucherId) As Voucher, "
+ "e.farmId.name As Farm, CONCAT(e.farmId.farmerId.firstName, ' ', e.farmId.farmerId.lastName) AS Farmer,"
+ " tia.seasonId.name Season, e.farmingActivityId.name As FarmingActivity FROM Enrollment e,"
+ " TemporaryInputsAllocated tia where e.farmId = tia.farmId"
+ " AND tia.voucherId NOT IN (SELECT DISTINCT(ia.voucherId) from InputsAllocated ia )";
When i run my code i get the error:
ERROR controllers.ContractApplicationController - java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [SELECT DISTINCT(tia.voucherId) As Voucher, e.farmId.name As Farm, CONCAT(e.farmId.farmerId.firstName, ' ', e.farmId.farmerId.lastName) AS Farmer, tia.seasonId.name Season, e.farmingActivityId.name As FarmingActivity FROM Enrollment e, TemporaryInputsAllocated tia where e.farmId = tia.farmId AND tia.voucherId NOT IN (SELECT DISTINCT(ia.voucherId) from InputsAllocated ia )], line 1, column 333: unexpected token [(].
Internal Exception: NoViableAltException(83#[1302:1: simpleSelectExpression returns [Object node] : (n= singleValuedPathExpression | n= aggregateExpression | n= variableAccessOrTypeConstant );])
I am running npgsql v3.7 with .NetCore on Ubuntu.
When I execute a select query and a cell in any row in the results is null, an exception is thrown with the error message "Column is null".
I am having to work around this by putting every column in the select clause inside a case statement which tests for NULL
"CASE WHEN " + fieldName + " IS NULL THEN '' ELSE " + fieldName + " END "
This seems a bit extreme and should not be necessary. Has anyone else come across this.
Thanks.
You are probably trying to read the column like this:
using (var reader = cmd.ExecuteReader()) {
reader.Next();
var o = reader.GetString(0); // Or any other of the Get methods on reader
...
}
This code will fail if the column contains a null, and is the expected behavior. In ADO.NET, you need to check for a null value with reader.IsDBNull(0) before actually getting the value. That's just how the database API works.
I don't know why NULL values are giving you errors, but you can do away with the ugly CASE statement in favor of using COALESCE:
"COALESCE(" + fieldName + ", '')"
Ideally you should make a configuration change such that NULL values do not cause this problem.
I am facing strange issue with raw SQLs, and I need some help to figure out the best way to fix it. I could, of course, add the columnMappings, but I want to make sure it's not because I am doing something wrong.
Play Framework APP
Ebeans ORM
Postgresql 9.,4
Executing the following RawSQL against a Postgresql database fails if I don't define columnMappings, although I have an alias defined:
String sql
= " Select date_trunc('day', end_time) as theDate, "
+ " count(*) as value "
+ " From ebay_item "
+ " group by date_trunc('day', end_time) ";
RawSql rawSql =
RawSqlBuilder
.parse(sql)
.create();
Error:
016-03-25 12:05:15,303 ERROR m.c.a.e.s.p.SimpleDBPromiseService - Error executing named query
javax.persistence.PersistenceException: Property [dateTrunc('day'] not found on models.com.abiesolano.ebay.sqlpojos.RangedDateCounter
If I switch to an H2 database:
String sql
= " SELECT trunc(end_time) as theDate, "
+ " count(*) as value "
+ " From ebay_item "
+ " Group by trunc(end_time)";
RawSql rawSql =
RawSqlBuilder
.parse(sql)
.create();
it works no problems.
Any suggestion would be really appreciated.
I don't think mysql likes to group or order by functions, you should use your alias "theDate" instead.
Note that if you're mapping to a bean object, the alias must be a #Transient property of your bean to be mapped by Ebean (otherwise, you'll get an unknown property error).
I have a CTE statement. When I try to execute in with classic asp the parameter is not replaced correctly:
Set cmd=Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = objConnection
cmd.CommandText = " my CTE is here"
cmd.CommandType = adCmdText
'adCmdUnspecified,adCmdText,adCmdTable,adCmdStoredProc,adCmdUnknown,adCmdFile,adCmdTableDirect
Set objParam = cmd.CreateParameter(, adBigInt , adParamInput ,8,CLng(MyParameter))
cmd.Parameters.Append objParam
When I get the final statement the "?" is not replace in the statement and it gives me error.
I try with each command type but no results.
The issue was caused by foolish syntax error in the "CommandText" string.