I am facing an error mentioned above, while fetching a list of values in a named query.
Here is the HQL syntax for this:
select rolepermis0_.permission_name as col_0_0_ from role_permission rolepermis0_ where rolepermis0_.role_id in ()
and here is the named query syntax i am using:
#NamedQuery(name = "rolePermission.getPermissionsByRoleIds",
//query = "SELECT NEW com.bitwise.tdm.project.internal.entity.Project(p.projectId, p.projectName,p.projectDescription) FROM UserProjectEntity up LEFT JOIN up.user u LEFT JOIN up.project p WHERE up.userId = :userId")
query = "SELECT rp.permissionName FROM RolePermissionEntity rp WHERE rp.roleId IN (:roleIds)")
Can someone please point out what am i missing in this?
Related
I am working on a long query that has multiple joins, and I am getting this error numerous times, can someone please assist? I went through every single solution online, but it doesn't seem to be my case. Below is an example where I am getting this "SQL compilation error: syntax error line 6 at position 75 unexpected 'on'"
select
clmt.CLAIMANT_NATURAL_KEY,
dlexp.LOSS_EXPOSURE_NATURAL_KEY,
min(rtncall.RETURNED_CALL_DATE_TIME_KEY) MIN_RETURN_CALL_DATE_TIME_KEY
from
PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_CLAIMANT clmt
left join
PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_CLAIM_CONTACT_RETURN_CALL rtncall on clmt.CLAIM_CONTACT_KEY = rtncall.CLAIM_CONTACT_KEY
left join
PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_LOSS_EXPOSURE dlexp on clmt.CLAIMANT_NATURAL_KEY = dlexp.CLAIMANT_NATURAL_KEY
where
rtncall.RETURNED_CALL_STATUS_CODE = 'CONTACTED'
and dlexp.CURRENT_RECORD_IND = 'Y'
group by
clmt.CLAIMANT_NATURAL_KEY, dlexp.LOSS_EXPOSURE_NATURAL_KEY
Non-formatted code here:
select
clmt.CLAIMANT_NATURAL_KEY
,dlexp.LOSS_EXPOSURE_NATURAL_KEY
,min(rtncall.RETURNED_CALL_DATE_TIME_KEY) MIN_RETURN_CALL_DATE_TIME_KEY
from PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_CLAIMANT clmt
left join PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_CLAIM_CONTACT_RETURN_CALL rtncall on clmt.CLAIM_CONTACT_KEY = rtncall.CLAIM_CONTACT_KEY
left join PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_LOSS_EXPOSURE as dlexp on clmt.CLAIMANT_NATURAL_KEY = dlexp.CLAIMANT_NATURAL_KEY
where rtncall.RETURNED_CALL_STATUS_CODE = 'CONTACTED'
and dlexp.CURRENT_RECORD_IND = 'Y'
group by
clmt.CLAIMANT_NATURAL_KEY
,dlexp.LOSS_EXPOSURE_NATURAL_KEY
How to solve this?
Thanks for the help in advance.
I tried some solutions from the snowflake community but can't find why this keeps happening.
select
clmt.CLAIMANT_NATURAL_KEY
,dlexp.LOSS_EXPOSURE_NATURAL_KEY
,min(rtncall.RETURNED_CALL_DATE_TIME_KEY) MIN_RETURN_CALL_DATE_TIME_KEY
from PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_CLAIMANT clmt
left join PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_CLAIM_CONTACT_RETURN_CAL
rtncall on clmt.CLAIM_CONTACT_KEY = rtncall.CLAIM_CONTACT_KEY
left join PNC_PSA_DB.KEDW_KSG_LOSS_CDC.D_LOSS_EXPOSURE dlexp on
clmt.CLAIMANT_NATURAL_KEY = dlexp.CLAIMANT_NATURAL_KEY
where rtncall.RETURNED_CALL_STATUS_CODE = 'CONTACTED'
and dlexp.CURRENT_RECORD_IND = 'Y'
group by
clmt.CLAIMANT_NATURAL_KEY
,dlexp.LOSS_EXPOSURE_NATURAL_KEY;
This code works as is and is syntactically right.
I get the error Incorrect syntax near ')' from the following SQL query:
SELECT
"GLPOST"."ACCTID",
"GLPOST"."FISCALYR",
"GLPOST"."FISCALPERD",
"GLPOST"."SRCELEDGER",
"GLPOST"."JRNLDATE",
"GLPOST"."BATCHNBR",
"GLPOST"."ENTRYNBR",
"GLPOST"."JNLDTLDESC",
"GLPOST"."JNLDTLREF",
"GLPOST"."TRANSAMT",
"APIBC"."POSTSEQNBR",
"APIBC"."CNTBTCH"
FROM ("MHLDAT"."dbo"."GLPOST" "GLPOST"
INNER JOIN "MHLDAT"."dbo"."GLJEH" "GLJEH"
ON (("GLPOST"."DRILSRCTY"="GLJEH"."DRILSRCTY")
AND ("GLPOST"."DRILLDWNLK"="GLJEH"."DRILLDWNLK")
AND "GLPOST"."DRILAPP"="GLJEH"."DRILAPP")))
INNER JOIN "MHLDAT"."dbo"."APIBC" "APIBC"
ON "APIBC"."POSTSEQNBR" = (CAST ("SUBSTRING" (CAST ("GLPOST"."DRILLDWNLK" AS "CHAR"(18)),3,CAST ("LEFT" (CAST ("GLPOST"."DRILLDWNLK" AS "CHAR"(18)),1) AS "INT" )) AS "INT" ))
WHERE
"GLPOST"."SRCELEDGER"=N'AP' AND "GLPOST"."FISCALYR"=N'2021' AND "GLPOST"."FISCALPERD"=N'01' AND "GLJEH"."ERRBATCH"=0
Any suggestions to resolve please?
SELECT
GLPOST.ACCTID,
GLPOST.FISCALYR,
GLPOST.FISCALPERD,
GLPOST.SRCELEDGER,
GLPOST.JRNLDATE,
GLPOST.BATCHNBR,
GLPOST.ENTRYNBR,
GLPOST.JNLDTLDESC,
GLPOST.JNLDTLREF,
GLPOST.TRANSAMT,
APIBC.POSTSEQNBR,
APIBC.CNTBTCH
FROM MHLDAT.dbo.GLPOST
INNER JOIN MHLDAT.dbo.GLJEH
ON GLPOST.DRILSRCTY=GLJEH.DRILSRCTY
AND GLPOST.DRILLDWNLK=GLJEH.DRILLDWNLK
AND GLPOST.DRILAPP=GLJEH.DRILAPP
INNER JOIN MHLDAT.dbo.APIBC
ON APIBC.POSTSEQNBR = CAST(SUBSTRING(CAST(GLPOST.DRILLDWNLK AS CHAR(18)),
3,
CAST(LEFT(CAST(GLPOST.DRILLDWNLK AS CHAR(18)),
1) AS INT)
) AS INT)
WHERE
GLPOST.SRCELEDGER = N'AP'
AND GLPOST.FISCALYR = N'2021'
AND GLPOST.FISCALPERD = N'01'
AND GLJEH.ERRBATCH = 0
You are using a lot of unnecessary parenthesis and double quoting, remove them (specially on the names of the functions SUBSTRING and LEFT). Remove the aliases (they are unnecessary because you use the same name as the table).
I have aligned your query so you can visually see where starts and ends every subexpression.
In my SSRS report builder I have an expression set for one of my dataset (name is dsTagAttributes). The query type is text.
This is the query expression
="select m.TagName, ta.descriptor, t.[State] from MasterTags m inner join TagAttributesClassic ta on m.ID = ta.TagID inner join TagStates t on t.ID = m.StateID where m.PIServerID = #ServerID and t.[State] = #State and m.MetaData1 = #Station " & Parameters!AndOr.Value & "m.MetaData2 = #Device"
The above query expression has a parameter which is concatenated in the select statement.
The parameter #AndOr data type is text, has a default value of "or", and parameter visibility is set to hidden (screen shot below). I have set this parameter because it will be used to dynamically change the dataset result from or to and during the report runtime.
But when I run the report, an exception is thrown saying,
What could go wrong in my query command text?
Any help is greatly appreciated.
You can run Profiler against Data Source to see the query.
I assume the problem is that you miss "'" before and after each varchar value (#State, #Station).
I wouldn't use that way to use OrAnd condition
You can modify TSQL like
...
AND
(m.MetaData2 = #Device AND #OrAnd = 'AND')
)
OR
(m.MetaData2 = #Device AND #OrAnd = 'OR')
Just make sure you place ')' and '(' correctly, depending on business logic.
I have this raw sql that I am trying to run on grails
final session = sessionFactory.currentSession;
final String query = 'select count(A.*) from Artifact as A LEFT JOIN classification as C on (A.id=C.artifact_id) where C.id IS NULL OR C.active=0';
final sqlQuery = session.createSQLQuery(query);
def totalunclass = sqlQuery.with {
addEntity(Artifact);
}
But I am getting the error Message: SQL queries do not currently support returning aliases
I tried another method but failed there too achieve the result click here
Try changing your query line to look like this
final String query = 'select count(*) from Artifact A LEFT JOIN classification C on (A.id=C.artifact_id) where C.id IS NULL OR C.active=0';
Try this and remove aliases:
final session = sessionFactory.currentSession;
final String query = 'select count(Artifact.*) from Artifact LEFT JOIN classification on (Artifact.id=classification.artifact_id) where classification.id IS NULL OR classification.active=0';
final sqlQuery = session.createSQLQuery(query);
def totalunclass = sqlQuery.with {
addEntity(Artifact);
}
how to converse access query to sql server query string by programing?
example for access query string
SELECT dbo_VNMST.VISITDATE, dbo_VNTREAT.TREATMENTCODE, dbo_VNMST.HN, dbo_VNMST.VN, dbo_VNTREAT_1.TREATMENTCODE, Count(dbo_VNMST.HN) AS CountOfHN, dbo_PATIENT_NAME.SUFFIX, Mid([firstname],2) AS FIRSTNAME1, Mid([lastname],2) AS LASTNAME1, (FIRSTNAME1+' '+LASTNAME1) AS FULLNAME
FROM (((dbo_VNMST INNER JOIN dbo_VNTREAT ON (dbo_VNMST.VISITDATE = dbo_VNTREAT.VISITDATE) AND (dbo_VNMST.VN = dbo_VNTREAT.VN)) INNER JOIN dbo_VNPRES ON (dbo_VNMST.VISITDATE = dbo_VNPRES.VISITDATE) AND (dbo_VNMST.VN = dbo_VNPRES.VN)) INNER JOIN dbo_VNTREAT AS dbo_VNTREAT_1 ON (dbo_VNMST.VISITDATE = dbo_VNTREAT_1.VISITDATE) AND (dbo_VNMST.VN = dbo_VNTREAT_1.VN)) INNER JOIN dbo_PATIENT_NAME ON dbo_VNMST.HN = dbo_PATIENT_NAME.HN
GROUP BY dbo_VNMST.VISITDATE, dbo_VNTREAT.TREATMENTCODE, dbo_VNMST.HN, dbo_VNMST.VN, dbo_VNTREAT_1.TREATMENTCODE, dbo_PATIENT_NAME.SUFFIX, Mid([firstname],2), Mid([lastname],2)
HAVING (((dbo_VNMST.VISITDATE) Between #9/1/1466# And #9/14/1466#) AND ((dbo_VNTREAT.TREATMENTCODE)="3964") AND ((dbo_VNTREAT_1.TREATMENTCODE)="92H") AND ((dbo_PATIENT_NAME.SUFFIX)=0));
In addition to what Kane posted, you'll also need to replace the underscore ("_") between dbo and the table name with a period ("."), e.g.:
SELECT dbo_VNMST.VISITDATE
will become
SELECT dbo.VNMST.VISITDATE
You'll need to use the SUBSTRING function instead of the MID function, replace double quotes with a single quote and remove the hash (#) identifier for your BETWEEN statement.