How to Sub query using BQL in Acumatica - acumatica

We want to translate this SQL to BQL in Acumatica with the use of PXFilteredProcessingJoin, how can we do this?
SELECT * FROM BAccount WHERE BAccount.BAccountID in (Select CQHRISTimekeepingBundyClock.Employee as 'BAccountID' from CQHRISTimekeepingBundyClock)

Looks like you don't need Sub Select in this case.
Inner join will be enough here.
PXSelectJoin<BAccount,
InnerJoin<CQHRISTimekeepingBundyClock, On<BAccount.bAccountID, Equal<CQHRISTimekeepingBundyClock.employee>>>,
Where<...>>
As for sub selects in general, you can do it in Acumatica using PXProjection attribute or PXDBScalar attribute.
Check ARInvoice or ARInvoiceWithDL DACs for reference.

Related

What is the difference, PXSelector vs PXDBScalar

I'm trying to figure out when to use PXDBScalar. Do you guys know the difference between PXSelector and PXDBScalar and when to use which one?
In short PXDBScalar is normally used for unbound DAC fields (not stored in the table). For example if you wanted to have a Vendor name handy within a DAC fetch you could configure a DAC field with the vendor name without having to actually store it in the table. Also this works well with GI's.
PXSelector is an attribute for a DAC field that will allow the GUI to perform a look up of 'possible values' as related to the field.
The below explanations are from help.acumatica.com.
PXDBScalar:
Defines the SQL sub request that will be used to retrieve the value for the DAC field.
You should place the attribute on the field that is not bound to any particular database column.
The attribute will translate the provided BQL Search command into the SQL sub request and insert it into the select statement that retrieves data records of this DAC. In the BQL command, you can reference any bound field of any DAC.
Note that you should also annotate the field with an attribute that indicates an unbound field of a particular data type. Otherwise, the field may be displayed incorrectly in the user interface.
You should not use fields marked with the PXDBScalar attribute in BQL parameters (Current, Optional, and Required).
PXSelector:
Configures the lookup control for a DAC field that references a data record from a particular table by holding its key field.

ARInvoice.CustomerLocationID

The ARInvoice DAC has a field CustomerLocationID. The SQL table ARInvoice does not have a field CustomerLocationID. I have created a SQL View to create a custom DAC from and I need to set the CustomerLocationID from an invoice, in the SQL View, equal to a value to return the correct results. What SQL table holds the field ARInvoice.CustomerLocationID?
ARInvoice herits from ARRegister Class which contains CustomerLocationID field.
Because ARInvoice uses this field it is declared as new abstract in it's class definition:
Using Views is against Acumatica Standard. It is recommended that you create a DAC that is a PXProjection.
Here is an asiablog post about them.
You can find the LocationID in BAccount.
Select the BAccount where the BAccountID is equal to the CustomerID of the Invoice. The field is DefLocationID.
Use the BAccountR DAC to prevent caching issues.

acumatica report designer union tables

Is there a way in Acumatica report designer to union two tables? I find that you have to link table to use them in reports. For example can you get data based on a date range from AP Invoice and AR Invoice without having a third table to link them together?
Thanks
A DAC created over a SQL VIEW with UNION ALL and added to ReportDesigner is likely the best approach, but perhaps a FULL JOIN will work for your purpose.
This link describes Full Join or Union All:
https://www.tutorialspoint.com/sql/sql-full-joins.htm
For your example in ReportDesigner, APInvoice could be FULL JOIN to ARInvoice on FinPeriod and Vendor/Customer on relationships tab, offer From/To date range parameters on parameters tab with defaults such as #monthStart and #monthEnd. Conditions tab could limit results to WHERE DocBal NotEqual 0. Display textboxes could use an IsNull such as:
=IsNull([APInvoice.DocBal],[ARInvoice.DocBal])

Embed native sql inside cognos frameowrk manager that accepts a parameter

I need to embed a native oracle sql statement inside COGNOS framework manager. This link describes how to do it.
e.g:
select cust_name from cust where cust_id = '111'
http://businessintelligence.ittoolbox.com/groups/technical-functional/cognos8-l/native-query-in-framework-manager-query-subject-2374263
Now is there a way to embed an SQL inside COGNOS FM that also accepts a parameter.
e/g:
select cust_name from cust where cust_id = ?
You can use the prompt macro as described here:
Creating prompts with query macros
Your expression should look something like this:
select cust_name from cust where cust_id = #prompt('prmCutsId','integer')#
Ofcourse you can expand it by providing default value, or use the promptmany macro so supply list of values (and not just one value).
You can really do nice things with macros in Cognos, but you have to know exactly what you are doing.

Excel: Use a cell value as a parameter for a SQL query

I'm using MS Excel to get data from a MySQL database through ODBC.
I successfully get data using an SQL query. But now I want that query to be parameterized.
So I wonder If it is possible to use a cell value (a spreadsheet cell) as a parameter for such a query.
For example, for this query:
select name from user where id=1
I'd like to get the id value from, say, cell D4 in the spreadsheet.
Is that the proper approach to parameterize a query? and how can I do it?
Thanks.
I had the same problem as you, Noboby can understand me, But I solved it in this way.
SELECT NAME, TELEFONE, DATA
FROM [sheet1$a1:q633]
WHERE NAME IN (SELECT * FROM [sheet2$a1:a2])
you need insert a parameter in other sheet, the SQL will consider that information like as
database, then you can select the information and compare them into parameter you like.
If you are using microsoft query, you can add "?" to your query...
select name from user where id= ?
that will popup a small window asking for the cell/data/etc when you go back to excel.
In the popup window, you can also select "always use this cell as a parameter" eliminating the need to define that cell every time you refresh your data. This is the easiest option.
queryString = "SELECT name FROM user WHERE id=" & Worksheets("Sheet1").Range("D4").Value
The SQL is somewhat like the syntax of MS SQL.
SELECT * FROM [table$] WHERE *;
It is important that the table name is ended with a $ sign and the whole thing is put into brackets. As conditions you can use any value, but so far Excel didn't allow me to use what I call "SQL Apostrophes" (´), so a column title in one word is recommended.
If you have users listed in a table called "Users", and the id is in a column titled "id" and the name in a column titled "Name", your query will look like this:
SELECT Name FROM [Users$] WHERE id = 1;
Hope this helps.

Resources