MarkLogic: How to manage additional query in constraint - xquery

MarkLogic 9.0.8
On UI, apart from search text, few filters are applied including publish date year.
As we can't control how end user will write query in multiline textbox.
So at end query look like something
AU:Manish AND PY:>=2001 AND CT:Control AND UT:uncontrol AND PY:<=2010
(AU:Manish AND PY:>=2001) OR (CT:Control AND UT:uncontrol AND PY:<=2010)
AU:Manish AND CT:Control AND UT:uncontrol AND PY:>=2001 AND PY:<=2010
Till now we managed with having year range at the end in query and was working with following code
Qyery: AU:Manish AND CT:Control AND UT:uncontrol OR PY:>=2001 AND PY:<=2010
<additional-query>
{
cts:and-query((
cts:path-range-query("contg/sortdate/yr", ">=",xs:int($startYear)),
cts:path-range-query("contg/sortdate/yr", "<=",xs:int($endYear))))
}
</additional-query>
But now as user can put year range anywhere in the query text, its not working as expected
So can we write condition in constraint directly and how to put additional query inside ?
<constraint name="Year">
<range type="xs:int" facet="false">
<path-index>article/date/year</path-index>
</range>
</constraint>
Expected Behavior
If user pass year range then it should return documents within given range
if not then it will not apply year range

Related

How can I calculate a field based on fields in other tables while inserting a record (in a procedure)

I'm sorry for the confusing title, but couldn't find another way to ask it.
Let's say I want to write a procedure add_salesline. I enter all the fields with parameters, except subtotal. Subtotal (just the price for the salesline) needs to be calculated based on fields in other tables such as productprice in the table products, pricereduction in the table promotion, etc. (based on the properties).
How can I do this? I've been trying to solve this problem for a good week now, and it's just not working...
Presumably one of the parameters passed to procedure add_salesline() is productid, or whatever. So you use that to SELECT products.productprice, promotion.pricereduction and whatever else you need to perform the calculation.
The purpose of writing a stored procedure is to associate several calls into a single program unit. So add_salesline() might look something like this (lots of caveats because your question is very light on details):
create or replace procedure add_salesline(
p_orderno in salesline.orderno%type
, p_salesqty in salesline.salesqty%type
, p_productid in products.productid%type
)
is
new_rec salesline%rowtype;
begin
new_rec.orderno := p_orderno;
new_rec.salesqty := p_salesqty;
new_rec.productid := p_productid;
select p_salesqty * (p.productprice * nvl(pp.pricereduction, 1))
into new_rec.subtotal
from products p
left outer join promotion pp
on pp.productid = p.productid
where p.productid = p_productid
;
insert into salesline
value new_rec;
end;
This code assumes pricereduction is a rate. If the value is an absolute discount the formula will be different (p.productprice - nvl(pp.pricereduction, 0)). Or if it's a replacement price: coalesce(pp.pricereduction, p.productprice).

how to call bapi in se37 and give output of bapi to another bapi

I have 3 bapi named BAPI_SALESORDER_GETLIST,BAPI_SALESORDER_GETSTATUS and BAPI_SALESORDER_GETDETAILBOS.
Here in the first bapi I have to input Customer Number and Sales Organization as input and retrieve Sales Document Number (SD_DOC) and from_Date.
This Sales Document Number(SD_Doc) retrieved from 1st BAPI has to be given as input to other bapi named BAPI_SALESORDER_GETSTATUS to retrieve some data.
and the same Sales Document Number has to be given input to the third BAPI that is BAPI_SALESORDER_GETDETAILBOS to retrieve some particular data.
To my knowledge I have done some work with the bapi and up till now in the service I have created I have given only customer number as input to the URI in the SAP GATEWAY CLIENT
for example:
/sap/opu/odata/sap/ZOPENSALESORDER_SRV/openSalesOrderSet?$filter=Customerno eq '1'
If anyone can help regarding this would be very grateful for that.
First of all i would like to tell you guys that I have THREE bapis out of which i rquired my data.1)BAPI_SALESORDER_GETLIST 2)BAPI_SALESORDER_GETSTATUS and 3)BAPI_SALESORDER_GETDETAILBOS.
For the First Bapi i'll give input Customer Number(KUNNR) and Sales Organization(VKORG) , then i'll get sale document number as output.
This sales document number will be given to the next bapi BAPI_SALESORDER_GETSTATUS to obtain other relevant data.
And the same sales document number will also be given to the third bapi BAPI_SALESORDER_GETDETAILBOS.
I'll first tell you the steps
Specify the input parameters in the Import parameter. In my scenario i have kunnr and vkorg. click here for the image1
Then internal tables are already made as i'm only going to use the standard bapi's. so in table section just write the name of you bapi and you are good to go.click here for the image2
Then in the source section start your coding:
enter code here
DATA: "lt_bapiorders TYPE TABLE OF bapiorders,
lt_statusinfo TYPE TABLE OF bapisdstat,
lt_orderitem TYPE TABLE OF bapisditbos,
lt_orderscheduleline TYPE TABLE OF bapisdhedu.
FIELD-SYMBOLS: <lfs_order> TYPE bapiorders,
<lfs_statinfo> TYPE bapisdstat,
<lfs_orderitem> TYPE bapisditbos,
<lfs_orderscheduleline> TYPE bapisdhedu.
"Fecth all the sales order for a customer
CALL FUNCTION 'BAPI_SALESORDER_GETLIST'
EXPORTING
customer_number = kunnr
sales_organization = vkorg
TABLES
sales_orders = order.
"Get status for the sales order
LOOP AT order ASSIGNING <lfs_order> .
IF <lfs_order> IS ASSIGNED.
WRITE:/ <lfs_order>-sd_doc.
"This function call is for getting the status of the
"Sales document number derived from the BAPI_SALESORDER_GETLIST
CALL FUNCTION 'BAPI_SALESORDER_GETSTATUS'
EXPORTING
salesdocument = <lfs_order>-sd_doc
TABLES
statusinfo = lt_statusinfo.
APPEND LINES OF lt_statusinfo TO statusinfo_lt.
"Read Processing and delivery Status
READ TABLE lt_statusinfo ASSIGNING <lfs_statinfo> INDEX 1.
IF sy-subrc EQ 0.
WRITE: / 'Delivery Status', <lfs_statinfo>-dlv_stat_h,
'Required Date', <lfs_statinfo>-req_date_h,
'Delivery Number',<lfs_statinfo>-deliv_numb,
'Delivery Date',<lfs_statinfo>-deliv_date.
ENDIF.
CALL FUNCTION 'BAPI_SALESORDER_GETDETAILBOS'
EXPORTING
salesdocument = <lfs_order>-sd_doc
TABLES
orderitems = lt_orderitem
orderschedulelines = lt_orderscheduleline.
APPEND LINES OF lt_orderitem to orderitem.
"Read Processing and delivery Details
READ TABLE lt_orderitem ASSIGNING <lfs_orderitem> INDEX 1.
IF sy-subrc EQ 0.
WRITE: / 'Material', <lfs_orderitem>-material,
'Plant', <lfs_orderitem>-plant,
'Short-text',<lfs_orderitem>-short_text,
'Req_qty',<lfs_orderitem>-req_qty,
'doc_number',<lfs_orderitem>-doc_number.
ENDIF.
APPEND LINES OF lt_orderscheduleline to orderscheduleline.
"Read processing and delivery details -goods issue time
READ TABLE orderscheduleline ASSIGNING <lfs_orderscheduleline> INDEX 1.
IF sy-subrc EQ 0.
WRITE: / 'Goods Issue Date', <lfs_orderscheduleline>-gi_date.
ENDIF.
.
ENDIF.
ENDLOOP.
Then execute it.

asp.net SqlDataSource select statement with IN (...) clause

I need to pass a server-side parameter to my SqlDataSource SELECT IN-clause as follows (notice the parameter #InClause and it's location in the SQL-select that is defined in the aspx (for the SqlDataSource):
SELECT UID_REPORT, TXT_RPT_TEXT, TXT_RPT_NAME, TXT_RPT_ASPX_PAGE, TXT_RPT_TYPE
FROM REPORTS WHERE (UID_REPORT IN (#InClause))
ORDER BY INT_SORT_ORDER
But this does not pass validation in the Test-Query operation.
The '#InClause' parameter gets it's value from a HiddenField control.
I want to set this value based on some conditions. for example If DIVISION=5 then #InClause would ="45,46" Else ="14,15".
Any suggestions on how to pass the IN ( ... ) values by the hiddenfield.Value (which is a string, of course).
Thanks.
You need split string function to do this
SELECT uid_report,
txt_rpt_text,
txt_rpt_name,
txt_rpt_aspx_page,
txt_rpt_type
FROM reports
WHERE uid_report IN (SELECT split_value
FROM Udf_splitstring(#InClause, ','))
ORDER BY int_sort_order
Check the below links to create a split string function
http://sqlperformance.com/2012/07/t-sql-queries/split-strings
http://www.sqlservercentral.com/articles/Tally+Table/72993/
or of-course you can use dynamic sql

Using the MDX query builder in Visual Studio, how can I filter the parameters to choose '1/1/2010' - last month?

I have been trying to pass dynamic date parameters in SSRS's Visual Studio using SSAS and the Query Designer. I am trying to get my MDX query to pull from '1/1/2010' to last month using the CalendarMonth field. Here is my query:
SELECT
NON EMPTY
{
[Measures].[Full Case Quantity]
,[Measures].[Total]
,[Measures].[Verified Total]
} ON COLUMNS
,NON EMPTY
{
[PA Product].[PA Description].[PA Description].ALLMEMBERS*
[PA Product].[PA Product ID].[PA Product ID].ALLMEMBERS*
[Time].[Calendar Month].[Calendar Month].ALLMEMBERS*
[PA Product].[PA Uom].[PA Uom].ALLMEMBERS*
[Distributor].[Dist Name].[Dist Name].ALLMEMBERS*
[Time].[Calendar Year].[Calendar Year].ALLMEMBERS*
[Time].[Month Number Of Year].[Month Number Of Year].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM
(
SELECT
{[Concept OG].[Is Concept Display].&[1]} ON COLUMNS
FROM
(
SELECT
{[Concept].[Concept ID].&[6501]} ON COLUMNS
FROM
(
SELECT
NULL : StrToMember(#ToTimeCalendarMonth,CONSTRAINED) ON COLUMNS
FROM [Management]
)
)
)
WHERE
(
[Concept].[Concept ID].&[6501]
,[Concept OG].[Is Concept Display].&[1]
)
CELL PROPERTIES
VALUE
,BACK_COLOR
,FORE_COLOR
,FORMATTED_VALUE
,FORMAT_STRING
,FONT_NAME
,FONT_SIZE
,FONT_FLAGS;
Not sure what the problem is so need to do some digging!
If you run the following in SSMS what is returned? You will need to replace #ToTimeCalendarMonth with whatever your parameter is passing in:
SELECT
{} on 0,
NULL : StrToMember(#ToTimeCalendarMonth,CONSTRAINED) ON 1
FROM [Management]
The parameter will need to be something like this ... I don't know how the members in your cube look so this is a guess:
[Time].[Calendar Month].[Calendar Month].[200604]

Selecting values between 2 dates

I am currently working on a website that offers tutoring services and I have been stuck on this issue quite a while..
I have 2 text boxes where the user chooses a start date and a finish date, when the user clicks view he would be suppose to see the results in a gridview. I am using FormParameters to insert the date into the query.
SelectCommand of the sqldatasource
SelectCommand="SELECT [Session].Session_num AS Num, [Session].Session_Time_Stamp AS Session_Date, Student.Student_First & ' ' & Student.Student_Last AS Student FROM (([Session] INNER JOIN Student ON [Session].Student_Num = Student.Student_Num) INNER JOIN Class ON [Session].Class_ID = Class.Class_ID) WHERE ((([Session].Session_Time_Stamp) Between #firstdate And #seconddate))">
Parameters of the SqlDataSource
<SelectParameters>
<asp:FormParameter Name="firstdate" Type="DateTime"/>
<asp:FormParameter Name="seconddate" Type="DateTime"/>
</SelectParameters>
This is executed when the user clicks the view button, it is where I set the values of the parameters and execute the sql select.
Dim fdate As DateTime = Format(CDate(txtStartDate.Text), "MM/dd/yyyy")
Dim ldate As DateTime = Format(CDate(txtEndDate.Text), "MM/dd/yyyy")
gridTutor.SelectParameters("firstdate").DefaultValue = fdate
gridTutor.SelectParameters("seconddate").DefaultValue = ldate
gridTutor.Select(DataSourceSelectArguments.Empty)
gridTutorSessions.DataBind()
fdate and ldate are not empty, however after this is executed the query result is empty. Could it be that wrong methods to execute the select?
Edit: I realized the problem is probably with the query and DateTime format. When I transformed my textbox value to DateTime it put it like this #2/20/2014#. However, it doesn't return anything even if there are values between the two dates.
If anybody have an access query with DateTime I would like to see it. Thanks
I managed to fix it by formatting the date in my access database it's not the best solution but it is a fix for the situation
I believe you need to manually set fdate and ldate just before you do your 'selectparameters' (i.e. use "fdate = Format(CDate(txtStartDate.Text), "MM/dd/yyyy")". According to the following, values asigned to Dim in the manner you have would not reflect the realtime values you want. See the following regarding VB: "You can assign a value to a variable when it is created. For a value type, you use an initializer to supply an expression to be assigned to the variable. The expression must evaluate to a constant that can be calculated at compile time.

Resources