SAP B1 - Get Purchase Orders and Sales Orders containing item - sapb1

I need to find PO and SO using item code through Service Layer, but was not able to find a way to retrieve the items using a contain clause in child items.
Any ideas on how to build this query?

for sales order you should create view and expose service layer, and get view sl with parameter
1- create view
create view ORDERLINEB1SLQuery as
select ord.*, r1.ItemCode from ORDR ord inner join RDR1 r1 on r1.DocEntry=ord.DocEntry
2- expose this view in service layer
https://....:50000/b1s/v1/SQLViews('ORDERLINEB1SLQuery')/Expose
3- run view with ItemCode parameter
https://....:50000/b1s/v1/view.svc/ORDERLINEB1SLQuery?$filter=ItemCode eq 'A00006'

Related

I have to create a view with following attributes

Create a view named customer_mobile_details which has the following attributes. Display customer id,customer name,mobile number, sales id, net amount,model name and manufacturer name of the mobiles, they have purchased. Sort the records based on customer id,customer name,sales id in ascending order.enter image description here
My code is as below.
create view customer_mobile_details
as( select Customer_Info.Customer_ID, Customer_Info.Customer_Name,
Distributor.Mobilenumber,
Sales_Info.Salesid, Sales_Info.Net_Amount,
Mobile_Master.Model_Name, Mobile_Master.Manufacturer
from Customer_Info
inner join Sales_Info
on Customer_Info.Customer_ID = Sales_Info.Customer_ID
inner join Mobile_Master
on Sales_Info.Price = Mobile_Master.Price
inner join Distributor
on Mobile_Master.Distributor_ID = Distributor.Distributor_ID)
order by Customer_Info.Customer_ID, Customer_Info.Customer_Name, Sales_Info.Salesid asc;
But i'm getting some error. It says
Failed Test
Test Case 2: Check the attribute name,constraints,sorting etc.
Can someone help me to figure it out where I made the mistake?
You can try this one. Works for me.
This is pretty self explanatory.
create view customer_mobile_details as
(select customer_id,
customer_info.customer_name,
customer_info.mobile,
sales_info.salesid,
sales_info.net_amount,
mobile_master.model_name,
mobile_master.manufacturer
from customer_info
join sales_info using(customer_id)
join mobile_master using(ime_no))
order by customer_id,
customer_info.customer_name,
sales_info.salesid;
The issue is actually in the question as the mobile number to be taken is the attribute named "Mobile" from the table 'Customer_info' and not the "mobilenumber" attribute from table 'Distributor'.

SQL Server: Issue on Data Return

As a novice SQL Server user, I ran into a problem that I did not know a solution to. I am trying to draw a master list of items and their cost. Some items have component items with their own cost, and those need to be called as well. However, whenever I try to include the component items, the query does not return items without components.
For example: I call 3 items from the query: A, B, and C. It displays their costs perfectly. However, I learn that Item C has a Component Item X. When I try to add a column for component item and it's cost, Items A and B are not returned in the query as they do not have a component item. I can't figure out why a NULL isn't placed when an item does not have a component item to accompany it.
Here is my query:
SELECT
T1.item_no, T2.item_cost, T1.component_item_no, T2.item_cost(2)
FROM
T1
INNER JOIN
T2 ON T2.item_no = T1.item_no
INNER JOIN
T2(2) ON T2.item_no = T1.component_item_no
I had to call T2 twice so I could call item cost for both the top level item as well as it's component.
Sample return data:
Change the INNER JOIN to LEFT JOIN for the component item table

Sql Server View show records with no data in certain tables

I have tables Products, Sales and ProductsInStores. ProductsInStores table keeps track of how many Products there are in each store. And I have a SalesProductsInStoresView with columns from tables Sales and ProductsInStores.
But there are also Products that come from a different chain of stores, so there's no ProductsInStores record for these products. So when the sale is made SalesProductsInStoresView doesn't show Sales if a Product doesn't have a ProductsInStores record.
Can I make my View show Sales with no ProductsInStores record, and just show empty cells on ProductsInStores columns, and if this is not possible what maybe other options do I have, I'm using Asp.Net MVC and Sql Server 2008.
Use Left Outer join
Select a.field1,b.field2
from tablea A
left outer join tableb b on b.fieldc = a.fieldc
this allows data to be returned from the inner table whilst maintaining a join to the outer table even if there is no data present.

IF/THEN logic in SQL statements

Building a Shopping Cart app. Some products have options, some don't. I visitor can purchase a product either with or without the associate option if that product does have options.
I have the following JOIN statement to pull all the relative data for the shopping cart output:
SELECT tblshopping_cart.cart_id,
tblshopping_cart.session_id,
tblshopping_cart.product_id,
tblshopping_cart.product_qty,
tblshopping_cart.product_option,
tblproducts.product_title,
tblproducts.product_price,
tblproducts.product_sale_price_status,
tblproducts.product_sale_price,
tblproduct_options.option_text,
tblproduct_options.option_upcharge
FROM tblshopping_cart
INNER JOIN tblproducts ON tblshopping_cart.product_id = tblproducts.product_id
INNER JOIN tblproduct_options
ON tblshopping_cart.product_option = tblproduct_options.option_product_id
WHERE tblshopping_cart.session_id = '$session_id'
ORDER BY tblshopping_cart.product_qty ASC
It works if all the products in the cart all have associated tblshopping_cart.product_option's that exists in the tblproduct_options table. If a product doesn't have a valid option, it only returns those that do.
By default, any product added without an option gets added to the cart with the value of "0" for the product_option value. If the site user does choose an option, the option value gets added instead.
What I need to do is pull in the Options information (text and upcharge) IF that row has a valid option_product_id.
You should use a LEFT JOIN if you don't want to require your record set to have a relationship to product_option.
It would look like this:
LEFT JOIN tblproduct_options
ON tblshopping_cart.product_option = tblproduct_options.option_product_id
Instead of doing an INNER JOIN against tblproduct_options you should be doing a LEFT OUTER JOIN so that you get both products with and without an associated option.

linqpad query to connect two entities in odata

I am using linqpad. I have an ODATA connected. The entities are listed in left pane with relationships. There are two entities called Products and Customers. I have to get all the product id starting with pid and names of all customers startin with b. There is a relationship between both. Product is a child of customer. How do I do? I am trying since two days but unable to figure it out. Anyone could help?
this is the base code. i dont no what to do further.
from p in products
where p.ProductId.StartsWith("Pid")
from c in customers
where c.Name.StartsWith("B")
select new
{
p.Pid,
c.Name
};
Can you please specify how you want the relation between the two entities to affect the result of the query? Do you expect the above to only returns products (with ID starting with a given value) and then only the customers for those products which name starts with a certain value?
Such a query is not expressible in OData unfortunately. You could request all products which ID starts with a specific value, and all the related customers. And then filter the customers on the client.
For example this will get you all the products which ID starts with a certain value and all their customers:
from p in products
where p.ProductId.StartsWith("Pid")
select new Product
{
ProductId = p.ProductId,
Customers = p.Customers
};