This question already has answers here:
How to pass parameters to query?
(2 answers)
Closed 4 years ago.
In iReport, i want to put the sql query in my parameter expression editor as following.
(!$P{securityGrading}.equals("0")) ? "SecurityGrading- " + "select description from [KRISADMIN].SecurityLevel where Level = $P{securityGrading}" : "SecurityGrading- Default to all"
But the iReport can't execute my sql query. I know it doesn't recognize my sql query since i'm using double quote but how do I get my query works in it?
The Problem which I see is in the addition of the parameter value.
Correct way would be
If Level Column is integer then -
(!$P{securityGrading}.equals("0")) ? "SecurityGrading- " + "select description from [KRISADMIN].SecurityLevel where Level =" + $P{securityGrading} : "SecurityGrading- Default to all"
If Level column is of type varchar
(!$P{securityGrading}.equals("0")) ? "SecurityGrading- " + "select description from [KRISADMIN].SecurityLevel where Level ='" + $P{securityGrading} +"'" : "SecurityGrading- Default to all"
You need to take care that the dynamic values supplied from the parameters in ireport need to find the legit SQL.
Hope that this helps.
Related
I have query in table.
For Example:
SELECT 1 AS pocet_zaznamu " + #[$Package::db]
+ ".ads.ea_meta_auta_sleva
I read data into project.
Now I have:
SELECT 1 AS pocet_zaznamu \" + #[$Package::db] + \".ads.ea_meta_auta_sleva
How I remove back slash from string?
I think you are trying to write an expression in the OLEDB Source SQL Command, but you are writing it in the wrong place.
You can simply add a variable of type string example #[User::strQuery], and change its EvaluateAsExpression property to True, click on the expression field and write the following expression:
"SELECT 1 AS pocet_zaznamu " + #[$Package::db] + ".ads.ea_meta_auta_sleva"
Now go to the OLE DB Source, and change the Data Access mode to SQL Command from variable and select #[User::strQuery]
I am having the following exception when passing the query through executereader:
incorrect syntax near )"...
How do I write the 0 here?
Here's the whole query:
string query = "select distinct BillNumber,PatientName,MobileNo,DueAmount from PaymentView where RequestDate between '" + fromDate.ToString("yyyy-MM-dd") + "' and '" + toDate.ToString("yyyy-MM-dd") + "' and DueAmount>'"+value+"')";
Extra Closing bracket at end of query. Also DueAmount should not be wrap into single quotes remove it.
and DueAmount>'"+value+"')";
------------^
Note : This may lead to SQL Injection attack, My suggestion is use Sql Parameter.
Trying to convert a number value to decimal, with two decimals (,00), in vba when selecting value from MS Access table.
The Quantity column is of type number and the code Im using to format it is
Dim rstBody As DAO.Recordset
Dim orderBodyQuery As String
orderBodyQuery = "SELECT distinct CONVERT(Decimal(9,2), Quantity) FROM " + mainTable + " WHERE [" + uniqOrderColumn + "] = """ + order + """"
Set rstBody = CurrentDb.OpenRecordset(orderBodyQuery, dbOpenSnapshot)
This results in the error:
Undefined function 'CONVERT' in expression
As the error describes Im guessing Im using the wrong syntax here (SQL Server) but I can't find how to do this.
Please help
For display (text) it would be:
Format([Quantity], "0.00")
To retrieve numeric values rounded by 4/5 to two decimals, it would be:
CCur(Format([Quantity], "0.00"))
To set the Format property, use:
"0.00", or just "Standard".
Surprise! Access doesn't use T-SQL.
I think you want the FORMAT() function.
What are differences between access sql
techonthenet.com/access/functions/
I have an asp.net webpage with an asp.net gridview with the following query:
SelectCommand="SELECT * from details2 as t2 WHERE (t2.OCC IN ('+ #txtCOUNTRY +') OR t2.DCC IN ('+ #txtCOUNTRY +')) and t2.ac='Y'"
The textbox txtCOUNTRY value can have the following values (for example):
'AR','ES'
However the parameter #txtCOUNTRY doesn't seem to be properly, written as the gridview shows nothing.
if I change it to (for example) it works:
SelectCommand="SELECT * from details2 as t2 WHERE (t2.OCC IN ('AR,'ES') OR t2.DCC IN ('AR','ES')) and t2.ac='Y'"
So I can only assume the #txtCOUNTRY parameter is incorrectly written.
Any ideas ?
When you pass the values 'AR','ES' via a SQL parameter, they will automatically be escaped which would make your query literally look for the value: 'AR','ES'.
See this: Parameterize an SQL IN clause
So in your case (since you have a comma separated list of values, each in single quotes):
SelectCommand = "SELECT * from details2 as t2 WHERE " &
"(','+#txtCOUNTRY+',' LIKE '%'','+t2.OCC+''',%' OR ','+#txtCOUNTRY+',' LIKE '%'','+t2.DCC+''',%') " &
"and t2.ac='Y'"
If you are not enclosing your values in single quotes (for example: AR,ES) then the query becomes a bit more readable as you are not having to escape the single quotes in your query:
SelectCommand = "SELECT * from details2 as t2 WHERE " &
"(','+#txtCOUNTRY+',' LIKE '%,'+t2.OCC+',%' OR ','+#txtCOUNTRY+',' LIKE '%,'+t2.DCC+',%') " &
"and t2.ac='Y'"
Edit to provide some clarity as to why this works.
So for example, providing AR,ES as the value for the #txtCOUNTRY parameter would yield a condition:
,AR,ES, LIKE *,[t2.OCC],* OR ,AR,ES, LIKE *,[t2.DCC],*
This condition would be a match if either t2.OCC or t2.DCC were either AR or ES because the pattern would be matched.
This provides a simple way to pass in a comma separated list as a parameter so your query isn't exploitable with a SQL injection.
How can I convert the following SQL query into HQL?
SELECT count(sa.AID)
FROM A sa
, B sal,C m
WHERE sa.AID = sal.AID(+) and sa.BID = m.BID and sa.AID ='0001'
You need to transfer each table/column into it's associated Entity/Class in JAVA, then build the query with Hibernate ORM as below.
Suppose
- The entity name for the table sa is saEntity, for the table B is bEntity, and for the table C is cEntity.
- The class name for the column AID is AidClass, and for the column BID is BidClass
Then the Hibernate ORM query can be written as per the following (I like formating HQL queries inside annotations on multiple lines to make it easier to read & adapt).
#Query( "SELECT COUNT(sa.AidClass) "
+ "FROM saEntity sa, "
+ " bEntity sal "
+ " cEntity m"
+ "WHERE sa.AidClass = sal.AidClass"
+ " AND sa.BidClass = m.BidClass "
+ " AND sa.AidClass ='0001'")
public List <?> runMyQueryMethod();
Try looking at the answer to this question.
HQL to SQL converter
Or this article may help..
https://forum.hibernate.org/viewtopic.php?t=972441
If you showed some of the mappings I could probably help with the HQL. You could just use
Session.CreateSQLQuery instead??