Writing queries in SAP B1 Query manager is quiet same as sql queries...
A straight query without filters(parameters) will look like this
SELECT T0.CardCode, T0.CardName, T0.OrdersBal
FROM OCRD T0
WHERE T0.CardType = 'C'
This query pulls data for Customer Open Order Balance Report.
In addition to this, if we require data for a range of customers, we need to put parameters to get the range.
SELECT T0.CardCode, T0.CardName, T0.OrdersBal
FROM OCRD T0
WHERE T0.CardType = 'C' AND
T0.CardCode BETWEEN '[%0]' AND '[%1]'
[%0] , [%1] are parameters of type BusinessPartners - CardCode.
In Query generator these parameters will be prompted to display the result set.
Notice that these parameters are prompted with Choose From List.
Here Choose From List will prompt CardCode of all Business Partners' , irrespective of the cardType 'C' or 'S' (Business Partner might be Customer(C) or Supplier(S) ).
But here we need the report of customers only.
For this we must modify the query with the following:
Note: Invoice is a document given by seller to the customer.
OINV table contains only customer details hence we are going to use this for parameterizing
/* SELECT FROM [dbo].[OINV] T0 */
DECLARE @fccode AS VARCHAR(100)
/* WHERE */
SET@ fccode = /* T0 .CardCode */'[%0]'
/* SELECT FROM [dbo].[OINV] T0 */
DECLARE @tccode AS VARCHAR(100)
/* WHERE */
SET @tccode = /* T0.CardCode */'[%1]'
SELECT T0.CardCode, T0.CardName, T0.OrdersBal
FROM OCRD T0
WHERE T0.CardType = 'C' AND
T0.CardCode BETWEEN @fccode AND @tccode
STORED PROCEDURE IN QUERY MANAGER:
DECLARE @a AS DATETIME;
DECLARE @b AS DATETIME;
DECLARE @TBL TABLE (num INT, val NVARCHAR(8));
WITH ABCD(num, val) AS
(SELECT 1, CONVERT(CHAR(8), MIN(T0.ShipDate),112)
FROM DBO.RDR1 T0
WHERE T0.ShipDate > = '[%0]'
UNION
SELECT 1, CONVERT(CHAR(8), MAX(T0.ShipDate),112)
FROM DBO.RDR1 T0
WHERE T0.ShipDate < = '[%1]')
INSERT INTO @TBL
SELECT * FROM ABCD ORDER BY num ASC
SET @a = CAST((SELECT val FROM @TBL WHERE num=1)AS DATETIME)
SET @b = CAST((SELECT val FROM @TBL WHERE num=2)AS DATETIME)
EXEC DBO.SP_NAME @a,@b
Reference:
730 960 - SAP Business One does not identify identity variables in long queries
955295 - Survey Variables Using Variables in SQL Query Definition
A straight query without filters(parameters) will look like this
SELECT T0.CardCode, T0.CardName, T0.OrdersBal
FROM OCRD T0
WHERE T0.CardType = 'C'
This query pulls data for Customer Open Order Balance Report.
In addition to this, if we require data for a range of customers, we need to put parameters to get the range.
SELECT T0.CardCode, T0.CardName, T0.OrdersBal
FROM OCRD T0
WHERE T0.CardType = 'C' AND
T0.CardCode BETWEEN '[%0]' AND '[%1]'
[%0] , [%1] are parameters of type BusinessPartners - CardCode.
In Query generator these parameters will be prompted to display the result set.
Notice that these parameters are prompted with Choose From List.
Here Choose From List will prompt CardCode of all Business Partners' , irrespective of the cardType 'C' or 'S' (Business Partner might be Customer(C) or Supplier(S) ).
But here we need the report of customers only.
For this we must modify the query with the following:
Note: Invoice is a document given by seller to the customer.
OINV table contains only customer details hence we are going to use this for parameterizing
/* SELECT FROM [dbo].[OINV] T0 */
DECLARE @fccode AS VARCHAR(100)
/* WHERE */
SET
/* SELECT FROM [dbo].[OINV] T0 */
DECLARE @tccode AS VARCHAR(100)
/* WHERE */
SET @tccode = /* T0.CardCode */'[%1]'
SELECT T0.CardCode, T0.CardName, T0.OrdersBal
FROM OCRD T0
WHERE T0.CardType = 'C' AND
T0.CardCode BETWEEN @fccode AND @tccode
STORED PROCEDURE IN QUERY MANAGER:
DECLARE @a AS DATETIME;
DECLARE @b AS DATETIME;
DECLARE @TBL TABLE (num INT, val NVARCHAR(8));
WITH ABCD(num, val) AS
(SELECT 1, CONVERT(CHAR(8), MIN(T0.ShipDate),112)
FROM DBO.RDR1 T0
WHERE T0.ShipDate > = '[%0]'
UNION
SELECT 1, CONVERT(CHAR(8), MAX(T0.ShipDate),112)
FROM DBO.RDR1 T0
WHERE T0.ShipDate < = '[%1]')
INSERT INTO @TBL
SELECT * FROM ABCD ORDER BY num ASC
SET @a = CAST((SELECT val FROM @TBL WHERE num=1)AS DATETIME)
SET @b = CAST((SELECT val FROM @TBL WHERE num=2)AS DATETIME)
EXEC DBO.SP_NAME @a,@b
Reference:
730 960 - SAP Business One does not identify identity variables in long queries
955295 - Survey Variables Using Variables in SQL Query Definition