I am want to use OR EXISTS clause in QueryBuildDataSource but i dont know how to use it.
I prepare sql query:
select * from LedgerJournalTable l
where
(
l.createdBy = '...' and l.WorkflowStatus != 99
)
or exists
(
select top 1 'x' from WorkflowWorkItemTable w
where l.RecId = w.RefRecId
AND w.REFTABLEID = 211
and w.USERID = '....'
)
and i try to build ax query
queryDS = LedgerJournalTable_ds.query().dataSourceTable(tableNum(LedgerJournalTable));
ledgerStatusFilter = queryDS.addRange( fieldnum(LedgerJournalTable,WorkflowStatus) );
ledgerUserFilter = queryDS.addRange( fieldnum(LedgerJournalTable,createdBy) );
ledgerStatusFilter.value( "!=99" );
ledgerUserFilter.value( "..." );
qbdsWorkItemtTable = queryDS.addDataSource( tablenum(WorkflowWorkItemTable) );
qbdsWorkItemtTable.joinMode( JoinMode::NoExistsJoin );
qbdsWorkItemtTable.addLink( fieldnum(LedgerJournalTable,RecId), fieldnum(WorkflowWorkItemTable,RefRecId) );
qbdsWorkItemtTable.addRange( fieldnum(WorkflowWorkItemTable,RefTableId) ).value( strfmt("%1",tablenum(LedgerJournalTable)));
workflowUser = qbdsWorkItemtTable.addRange( fieldnum( WorkflowWorkItemTable, UserId ) );
workflowUser.value("...");
info( strfmt("%1", queryDS.toString() ) );
sory for my bad English :c
Sorry, but AX queries do not support or exists.
Also see this similar question.
Related
I am using trying to populate a dropdown using magicVaueList hack and ExecuteSQl and I am having trouble with joining a text and number.
Here is my code:
MVL_Dropdown ( ExecuteSQL ( "select L.Product + GetAsText( L.Quantity )
from T08_ESTIMATES E
join T09_EST_LINE_ITEMS L on E.ID_Estimate = L.id_estimate
where E.ID_Estimate = ? "; ""; ""; T19_TASKS::preitem ) )
The trouble I get is with the + GetAsText( L.Quantity ) where I have also tried & GetAsText( L.Quantity ) will no results but if I was to remov ethe join like:
MVL_Dropdown ( ExecuteSQL ( "select L.Product
from T08_ESTIMATES E
join T09_EST_LINE_ITEMS L on E.ID_Estimate = L.id_estimate
where E.ID_Estimate = ? "; ""; ""; T19_TASKS::preitem ) )
Then it works minus the fact that I will need both values. I'm therefore certain the problem exists Concatenating my text and number but I'm quite new to FileMaker and not sure what to use to get it to work.
.
Any help appreciated.
For anyone wondering i had to use a double pipe like so:
L.Product || ' - ' || L.Quantity
MVL_Dropdown ( ExecuteSQL ( "SELECT L.Product || ' - ' || L.Quantity || ' off'
FROM T08_ESTIMATES E
JOIN T09_EST_LINE_ITEMS L ON E.ID_Estimate = L.id_estimate
WHERE E.ID_Estimate = ? "; ""; ""; T19_TASKS::preitem ) )
STRVAL - Converts a value of any type to a character string
Here I wanted to concatenate an integer "Quantity" and string "Units":
ExecuteSQL ( "
SELECT p.Description, STRVAL ( m.Quantity ) || p.Units
FROM JobMaterials m
JOIN Products p
ON m.kf_Product = p.kp_ProductID
WHERE m.kf_JobID = ?
" ;
"¦" ; "¶" ;
Jobs::kp_JobID
)
I need to compare one specific vertex to all other and print if they have exactly the same outE("Pertinent", "Secondaire")
here is the request i made :
SELECT $b
let $a = (
SELECT *
FROM Regle
WHERE titre="1823 - accessoires poids lourds tachygraphe"
),
$b = (
SELECT *
FROM Regle
WHERE out("Pertinent", "Secondaire") = $a.out("Pertinent", "Secondaire")
)
Thanks in advance
You could use
SELECT expand($b)
let $a = (
SELECT *
FROM Regle
WHERE titre="1823 - accessoires poids lourds tachygraphe"
),
$b = (
SELECT *
FROM Regle
WHERE out("Pertinent").#rid in $a.out("Pertinent").#rid and out("Secondaire").#rid in $a.out("Secondaire").#rid
)
Hope it helps.
This code throws an exception when rawVoters.Count() is called:
string sql = #"select * from Voters as v
inner join Homes as h on v.HomeID = h.ID
inner join Locations as l on h.LocationID = l.ID
inner join Streets as s on l.StreetID = s.ID
inner join Cities as c on s.CityID = c.ID
inner join VoterAgencies as va on v.CountyID = va.CountyID and v.VoterID = va.VoterID
where (va.AgencyID = #agencyID)
and (c.Name like '%' + #city + '%')
and (v.FirstName like '%' + #firstName + '%')
and (v.LastName like '%' + #lastName + '%')
and (s.Name like '%' + #street + '%')
and ((#voterID = 0) or (v.VoterID = #voterID))";
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add( new SqlParameter( "#agencyID", agencyID ) );
parameters.Add( new SqlParameter( "#city", model.City ) );
parameters.Add( new SqlParameter( "#firstName", model.FirstName ) );
parameters.Add( new SqlParameter( "#lastName", model.LastName ) );
parameters.Add( new SqlParameter( "#street", model.Street ) );
parameters.Add( new SqlParameter( "#voterID", model.VoterID ) );
IQueryable<Voter> rawVoters = _context.Voters
.AsNoTracking()
.FromSql( sql, parameters.ToArray() );
int numVoters = 0;
try
{
numVoters = rawVoters.Count();
}
catch( Exception e )
{
int i = 9;
i++;
}
The error message is:
"The column 'ID' was specified multiple times for 'v'."
I thought this might be because EF Core doesn't like the "as x" phrasing, so I substituted the table names for each of the identifiers...and got the same error message.
I'm curious as to what's going on here.
The problem was that the T-SQL was returning all fields (select *). Under EF Core, the returned fields must match the fields specified for the entity being returned, in this case Voter.
An inner join, like the one I was using, by default returns far more than just the Voter fields.
Changing the SQL to be select v.* (where v is the alias for Voters) solved the problem.
Hence you're just getting the Count,you can specify your column name as shown below.Then no issues :)
string sql = #"select v.ID from Voters as v
I have a query like :
select name, trunc( date, 'MM' ), sum( number )
from t$mytable
group by name, trunc( date, 'MM' );
which runs perfectly, and gives expected result.
I implemented exactly the same query in JPA criteria API :
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery criteriaQuery = criteriaBuilder.createQuery( pClass );
Metamodel metamodel = em.getMetamodel();
EntityType entityType_ = metamodel.entity( pClass );
Root<?> root = criteriaQuery.from( pClass );
Expression pathName = root.get( entityType_.getSingularAttribute( "name" ));
Path pathDate = root.get( entityType_.getSingularAttribute( "date" ) );
Expression<Date> pathTruncatedDate = criteriaBuilder.function("trunc", Date.class , pathDate, 'MM');
Expression pathNumber = criteriaBuilder.sum( root.get( entityType_.getSingularAttribute("number") ));
criteriaQuery.select( criteriaBuilder.array( pathName, pathTruncatedDate, pathNumber) );
List<Expression> groupBy = new ArrayList<Expression>();
groupBy.add( pathName);
groupBy.add( pathTruncatedDate);
criteriaQuery.groupBy( groupBy );
TypedQuery<Object[]> q = em.createQuery( criteriaQuery );
<-- and surprisingly I got ORA-00979: not a GROUP BY expression by running it. What coused the problem, everything is on right place, i guess.
Thank You very much in advance!
it's not look like Oracle question but,
what about creating view by your statement and using view in your application?
something like
create view vw_my_table as
select name, trunc( date, 'MM' ), sum( number )
from t$mytable
group by name, trunc( date, 'MM' );
I have same issue and have found the root cause of this ORA-00979.
Oracle automatically handle aggregation of date in below query
select name, trunc( date, 'MM' ), sum( number )
from t$mytable
group by name, trunc( date, 'MM' );
With Criteria API you need to use criteria builder least method.
In your cas you just need to replace select line with:
criteriaQuery.select( criteriaBuilder.array( pathName, criteriaBuilder.least(pathTruncatedDate), pathNumber) );
I have a tabe valued function called "GetLogInfosMsg" which I want to run provided with some Parameters from a specific table. The code below does not work; I get the message "Only one expression can be specified in the select list when the sub-query is not introduced with EXISTS.". Can somebody help me? Thanks.
SELECT
#pErrMsgID = [MsgID],
#pParams = [Params]
FROM
[dbo].[GetLogInfoMsg]((SELECT
[FIELD1],
[FIELD2],
[FIELD3]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID));
try this
you have to pass parameter in separate not in table format
SELECT #pErrMsgID = [MsgID] ,
#pParams = [Params]
FROM [dbo].[GetLogInfoMsg](( SELECT [FIELD1]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID
), ( SELECT [FIELD2]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID
), ( SELECT [FIELD3]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID
)) ;
If you are using mssql 2005+ consider using this:
SELECT
#pErrMsgID = t2.[MsgID],
#pParams = t2.[Params]
FROM [dbo].[TABLE1] t1
CROSS APPLY (SELECT [MsgID], [Params]
FROM [dbo].[GetLogInfoMsg] (t1.FIELD1, t1.FIELD2, t1.FIELD3) t2
WHERE t1.[UUID] = #pUUID