Query Generator in SBO 2007

Hi
I need to write a query based on sales orders but there are quite a few criteria
The user wants the ability to enter a date range, order number range and business partner range
The query I have is I want the report to produce all info if they leave the criteria blank
I am not sure how to do this.
Not sure if I need to use some sort of IF statement which basically says if a BP range has been entered then use it else ignore it, etc
Can anyone help me please ?
Thanks
Regards Andy

Hi,
When you specify the parameters in the query instead of the simple parameter you can use something like this:
WHERE (T0.DocDate >= '[%0]' or '[%0]' = '') and (T0.DocDate <= '[%1]' or '[%1]' = '')
Regards,
Nat

Similar Messages

  • Variables in SBO Query Generator

    Hi Expert,
    I have created a VIEW in SQL and querying this via SBO. I need to use FROM and TO Date inputs from the user.
    When using '[%0]' like I normally do, the query does not run.
    {/code}
    Declare @DateFrom as DateTime
    Declare @DateTo as DateTime
    Set @DateFrom = '[%0]'
    Set @DateTo = '[%1]'
    SELECT EARNER, PRODUCTLINE, Sum(LINETOTAL) AS 'Total', Sum(COMMISSION_PAYABLE) AS 'Total Commission'
    FROM [dbo].[COMMISSION]
    WHERE ([dbo].[COMMISSION].[DocDate] >= @DateFrom
    AND [dbo].[COMMISSION].[DocDate] <= @DateTo)
    Group by EARNER, PRODUCTLINE
    ORDER BY EARNER, PRODUCTLINE
    {/code}

    Using Date values duriectly through Variables is not possible due to the formats.
    So try this.
    Declare @DateFrom as DateTime
    Declare @DateTo as DateTime
    /* SELECT FROM [dbo].[OPCH] T0 WHERE */ SET  @DateFrom = /* T0.DocDate*/ '[%0]'
    /* SELECT FROM [dbo].[OPCH] T0 WHERE */ SET  @DateTo = /* T0.DocDueDate*/ '[%1]'
    SELECT EARNER, PRODUCTLINE, Sum(LINETOTAL) AS 'Total', Sum(COMMISSION_PAYABLE) AS 'Total Commission'
    FROM dbo.COMMISSION
    WHERE (dbo.COMMISSION.DocDate >= @DateFrom
    AND dbo.COMMISSION.DocDate <= @DateTo)
    Group by EARNER, PRODUCTLINE
    ORDER BY EARNER, PRODUCTLINE
    DocDate from OPCH is just an example.  You could use this syntax with any date field from any table.

  • Query report in SBO

    Dear Experts/Gurus,
    I have a problem in developing a report. The report I need is similar with general ledger report but some additional field need to add. If I use query, will it give the same report format with general ledger report in SBO ?
    In general ledger report, the format as follows:
    posting date           due date       Type    Details                               etc.. etc...
    <u>assets</u>       <u> ->1200</u>               <u>HSBC</u>
    ->01.01.04            ->01.01.04      PS      payment S-1211                 etc..etc....
    ->01.01.04            ->01.01.04      PS      payment S-1221                 etc..etc..
    The result of my query is as follows:
    Acctcode              Acctname          posting date    due date         etc..etc..           
    1200                       Asset              01.01.04         01.01.04
    1200                       Asset              01.01.04         01.01.04
    I could not understand that the underline words can't be available in report using query I created. Could the query generator be used to generate report where the underline word is also able to have in the report ? I really appreciate your answer so much. TIA
    Rgds,

    Jimmy,
    If you are using the SAP Query Manager, then no, you will not get the same formatting as a report that you would create using the Print Layout Designer (PLD) in Business One.  The query generator is just like it sounds and is similar to running a query within SQL itself.
    The forum that you have posted your question in is for questions related to the SAP Business One SDK.  Your question seems to be application related and should be posted in the SAP Business One Discussion Forum at ...
    http://cpsn-channel.sap.com/businessoneforum
    Eddy

  • Freight on percent basis in the marketing documents in SBO 2007 SP 0 PL7

    Dear All,
    Can I calculate a freight on percent basis in the marketing documents in SBO 2007 SP 0 PL7?

    By FMS , I mean Formatted Search Query.
    You can learn more about, SAP Business One Formatted Search Query from this link
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5cae89f9-0901-0010-64be-f37d9a7eed7b]

  • About query generator.

    SAP B1 2007 A PL46
    Hi All,
    I have many questions about query generator :
    1. It is possible to use or to call a stored procedure ? If yes, how can we implement this ?
    2. I try to use this query :
    declare @commercial integer
    set @commercial = [%0]
    declare @prjbegin nvarchar(20)
    set @prjbegin = '[%1]'
    declare @prjend nvarchar(20)
    set @prjend = '[%2]'
    SELECT T2.[DocNum], T2.[DocDate], T2.[CardCode], T2.[CardName], T3.[ItemCode], T3.[Dscription], T3.[Quantity] FROM [dbo].[OINV]  T2 INNER JOIN [dbo].[INV1]  T3 ON T2.DocEntry = T3.DocEntry WHERE T2.[SlpCode] =@commercial AND  T3.[Project] >=@prjbegin AND  T3.[Project] <=@prjend
    but it don't work. How can we do to use this ?
    Thanks for your help.
    Best regards.
    Michael

    Hi,
    I try this but it's not working :
    declare @commercial integer
    set @commercial = (SELECT SlpCode FROM OSLP WHERE SlpCode=[%0])
    declare @prjbegin nvarchar(20)
    set @prjbegin = 'N000001'
    declare @prjend nvarchar(20)
    set @prjend = 'R000003'
    SELECT T2.[DocNum], T2.[DocDate], T2.[CardCode], T2.[CardName], T3.[ItemCode], T3.[Dscription], T3.[Project] FROM [dbo].[OINV]  T2 INNER JOIN [dbo].[INV1]  T3 ON T2.DocEntry = T3.DocEntry WHERE T2.[SlpCode] =@commercial AND  T3.[Project] >=@prjbegin AND  T3.[Project] <=@prjend
    I have an error that is : you must specify a table name where execute the selection ...
    I think we can't use %0 and the statement DECLARE.
    Thanks
    Michael

  • Query Generator Funny error message

    Hello Experts, Not sure if you ever seen something like this, but be great if anyone can offer me some insight...
    on a normal query with parameter I have something like thsi
    /*select from ORDR t0*/
    declare @begandate as datetime
    /* where */
    set @begandate = /* t0.docdate*/ '[%0]'
    and it runs fine with just about any table, view...etc.. But as soon as you have a UDT in SBO... put in like
    /*select from ORDR t0*/
    declare @begandate as datetime
    /* where */
    set @begandate = /* t0.docdate*/ '[%0]'
    select * from dbo.[@bos_del_pri] a inner join ordr b on b.u_prioritycode = a.code
    where b.docdate = @begandate
    it give me funny error messages, "Only one epxression can be specifed in the select list when the subquery is not intrudoced with Exist"
    This is ran at a SBO 2005B PL35... when I ran a similar query in SBO 2005A PL45 I get soemthing like
    "must specify table to select from".. I know this error message doesn't make sense, but not sure if anyone has encounter the same problem, and if yes possible solutions?
    Thank You

    Hello Friends,
    This is in accordance to provide the information that Query Generator does not work with parameters and User defined tables together. As per my experience in SQL UDT tables start with "@" and variables declared in SQL are also prefixed with "@" so SQL does not make any difference between UDT of SAP and variable of SQL. Thus we are not able to use ([%0] parameters and UDT tables) together.
    Please correct me if I am wrong.
    Please forgive me if i have posted wrong information  
    I look forward to your reply.
    Regards,
    Murtaza

  • Query generator used to make general total and row total

    Dear experts/gurus,
    I have a problem how to create general total and total field in row by using query generator. In inventory in warehouse report of SBO 2004A SP 00 PL 41, there are total row of price x quantity / warehouse (if selection criteria is warehouse) and general total. I have made query report that quite similar with inventory in warehouse report using query generator and put selection criteria and item but I still can't find out the solution. is it possible using query generator to do that or if I use query analyzer, what is the code that I have to put ? is it compute sum(qty x price) by itemcode or there is stil another ? i appreciate your answer. TIA
    Rgds,

    Hi Jimmy,
    Here's one approach to solve your problem:
    = = = = = = =
    select oitm.itemcode, oitm.itemname, whs.whscode, whs.quantity
    from oitm inner join
    (select itemcode, sum(onhand) as quantity, whscode from oitw group by itemcode, whscode) whs
    on oitm.itemcode=whs.itemcode
    = = = = = = =
    ...the main query refers to the subquery as it was another table. The subquery calculates quantity per warehouse from the oitw table.
    Of course you could create a view in SQL Server instead of a subquery. That would make the query inside B1 query generator more simple and would also make it faster to execute.
    Henry

  • Declare func on Query Generator

    Hi,
    I am Using SAP B1 for hana ver 9.0 PL10
    I have a difficulty to use Declare function as variable reference in Query Generator, Any tips for this matter ?
    Thanks

    You can do this using the SAP Business One Query Manager. The code below calls a stored procedure with one parameter of the DateTime type, which the user is prompted to enter:
          declare @tmp as nvarchar(100)
          select @tmp = T0.Name from [@ADV] T0
          WHERE T0.U_Date = '[%0]'
          EXEC myReport '[%0]'
    The table @ADV is used just to let SBO know that the actual type of the [%0] parameter is Date.

  • Upgrading SBO-2005 B PL-05 to SBO-2007 B

    Dear all,
    Can you please tell me that u2013
    u201CDirectly running SBO-2007 B installation over SBO-2005 B PL-05 is an upgrade process or upgrade process means something else?

    Directly running SBO-2007 B installation over SBO-2005 B PL-05 is not the proper way to upgrade.
    Take the backup of ur 2005 b data base.
    run the upgrade query..
    if it gives any result solve the problem as per the result of query,if not returing any result measns ur data base is consistant.
    Then download the IRU tool,
    Install the IRU server and IRU clinet.
    Read the help of IRU to get more information.
    then run the upgrade exe.
    if u will directly run the 2007 b upgrade exe,it will craete problem in new data base,
    Hope this will help you.
    Regards,
    Neetu

  • CAN WE HAVE IF CONDITION IN QUERY GENERATOR

    Hi friends,
    am, trying to make use of if condition to obtain a set of values in query generator.  Its possible to retrieve the required result set using query analyser but not in query generator.  am trying to execute the following query
    if exists (select owor.u_reactor from owor,oitt where oitt.code=owor.itemcode and owor.u_reactor = 1 and owor.itemcode = '100-100')
    begin
                    select itt1.u_reactor1 from oitt,itt1 where itt1.father = oitt.code and itt1.father = '100-100'
    end
    else
    if exists (select owor.u_reactor from owor,oitt where oitt.code=owor.itemcode and owor.u_reactor = 2 and owor.itemcode = '100-100')
    begin
         select itt1.u_reac_23 from oitt,itt1 where itt1.father = oitt.code and itt1.father = '100-100'
    end
    else
    if exists (select owor.u_reactor from owor,oitt where oitt.code=owor.itemcode and owor.u_reactor = 3 and owor.itemcode = '100-100')
    begin
         select itt1.u_reactor4 from oitt,itt1 where itt1.father = oitt.code and itt1.father = '100-100'
    end
    if it is not possible to write such query in query generator  can someone help me with a workaround solution.
    Thank u
    Vaitheeswaran

    Hi,
    I dont think Nested IF Statements are allowed in PLD. The reason that u get the result in Query analyser and not in Query Generator is that SAP supports Transact SQL and many SQL Server 2000 functions are not supported.
    However there is a work around in Print Layout Designer for using IF condition by having Linked Objects. Kindly see some tutorials regarding Linked fields available on SDN site and think of some other way of implementing this nested IF query.
    Regards
    Rizwan Hafeez
    Team Lead
    SAP Addon Development Section
    Abacus Consulting - Pakistan

  • How to write a SQL query in SAP B1 2007 B with input parameters?

    How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?

    The syntax like
    SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
    Thanks,
    Gordon

  • How to do this in Query Generator?

    Dear Experts,
    Please check my following query I've written in Query Generator.
    /* select from dbo.OCRD t0 */
    declare @BP nvarchar(20)
    set @BP=/* t0.CardName */ '[%0]'
    declare @Dt1 datetime
    declare @Dt2 datetime
    set @Dt1=/* Start Date */ [%1]
    set Dt2=[%2]
    select distinct t1.po, Max(t1.supplier) Supplier,Max(t1.process) Process, Max(t1.OrderNo) OrderNo,Max(t1.Date) Date,
    isnull((select sum(t2.Quantity) from dbo.ir t2 where t2.po=t1.po and t2.TType<0),0) Issued,
    isnull((select sum(t3.Quantity) from dbo.ir t3 where t3.po=t1.po and t3.TType>0),0) Received,
    isnull((select sum(t2.Quantity) from dbo.ir t2 where t2.po=t1.po and t2.TType<0),0)-isnull((select sum(t3.Quantity) from dbo.ir t3 where t3.po=t1.po and t3.TType>0),0) Balance
    from dbo.ir t1 where t1.Supplier=@BP and (t1.Date>=@Dt1 and t1.Date<=@Dt2) group by t1.po
    The Query works well. But for the the lines
    set @Dt1=/* Start Date */ [%1]
    set Dt2=[%2]
    it displays BP Code as the prompt next the text boxes meant for inputting dates. I would like to display 'Start Date' and 'End Date' respectively for Dt1 and Dt2.
    Please explain me how to go about it.
    Thanks in advance.
    Regards
    Anand

    declare @Dt1 datetime
    set @Dt1=/* Start Date */ [%0]
    declare @Dt2 datetime
    set @Dt2=/* End Date */ [%1]
    /* select from dbo.OCRD t0 */
    declare @BP nvarchar(20)
    set @BP=/* t0.CardName */ '[%2]'
    I've changed. When I run the query the input box does not appear, the query shows only a blank table.
    Thanks
    Anand

  • Difference in Query generated by OBIEE for same report

    Hi,
    I am using a a report(X) in a filter condition.
    I am seeing a peculiar issue with OBIEE server. When i am running a report(X) alone, the query generated is different. But when i am using the same report in filter condition of other report(Y), the same report is generating some other query. The first report(X) is running fine but the second(Y) is not running at all.
    Case 1(Report X) Query: The report is breaking into 3 parts for different fact tables and combining the data to give result.
    Case 2(Report Y): A single query is being formed and within it is fecthing the data from different fact tables using subqueries.
    Case2 is creating a lot of problem as the performance is totally poor.
    Any suggesstions??
    Thanks
    Tataji

    Hi, we haven't debugged the application or traced the query against the production server (it's in our customer's office) buy I think there's no difference since the query itself has been tested using sqldeveloper against both servers (XE 11.2 and Enterprise 11.1) and the behavior is consistent. By consistent I mean:
    - The query executed via sqldeveloper against Oracle XE 11.2 runs ok and so does the application.
    - The query executed via sqldeveloper against Oracle Enterprise 11.1 fails with an ORA-01790 error, and so does the application (exceptions are being logged in the Event Log).
    To sum up: the same query runs ok in Oracle XE 11.2 and fails in Oracle Enterprise 11.1.
    Additional information: we have tried explicit casting the NULL literals to the corresponding data types (in the UNION ALLs) and the query works fine in both versions. ¿Is there an option in ODAC to tell the query generator to write this explicit castings?
    Regarding the DB schema and the LINQ query, I'll be sending them asap.
    Regards,
    Ernesto.

  • How to define the PLD of a Query generator report

    Hi All,
    I want to define the PLD of a Query Report. Currently I am Convertning it to Excel format. But my client wants it in PLD format.  so please tell me the process of defining the PLD for a Query generator Report.
    Thanks & Regards
    Pankaj Sharma.

    Hi,
    When u wrote yr query at that time save yr query
    Now yr query is save in "Query Manager"
    Open Query Manager > select yr query
    There is a button "Create Report"
    Create USer Report Window is display "define yr name" and select "Base Temple"
    once u save it double click and edit yr PLD....
    Hope it a best way to create uer PLD
    Thanks
    Kevin

  • Error in Query generator

    Dear all,
    I face an issue in Query generator.
    When i execute the query in query generator, the error is like this
    1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
    'Service Contracts' (OCTR)
    My query is like this
    Declare @StartYear as char(4)
    Declare @EndYear as char(4)
    Declare @Dept as char(3)
    Declare @UnitBusiness as char(3)
    Begin
    set @StartYear = (Select   YEAR(T0.[RefDate]) from JDT1 T0 where T0.[RefDate] = [%0] )
    set @EndYear =  (Select YEAR(T1.[RefDate]) from JDT1 T1 where T1.[RefDate] = [%1])
    set @Dept =  (Select T2.[Name] from OASC T2 where T2.[Name] = [%2])
    set @UnitBusiness = (Select   distinct SUBSTRING(T3.[Segment_0],10,2)  from OACT T3 where ( T3.[Segment_0] = [%3] OR ( 1 = (CASE WHEN [%3]  = 'All'  THEN 1 ELSE 2 END) ) ))
    Exec NEC_RPT_FinanceReport @StartYear,@EndYear,@Dept,@UnitBusiness
    End
    The problem is i can not show the input screen after i execute the query generator.
    If i remove the the Variable @Dept and replace with the value it runs well.
    Does any one know where is the problem ?
    Thanks in advance
    Regards
    Bodhi86

    HI Neetu, i have change the query without using store procedure
    my query is like this
    Declare @StartYear as char(4)
    Declare @EndYear as char(4)
    Declare @Dept as char(3)
    Declare @UnitBusiness as char(3)
    Begin
    set @StartYear = (Select   YEAR(T0.[RefDate]) from JDT1 T0 where T0.[RefDate] = [%0] )
    set @EndYear =  (Select YEAR(T1.[RefDate]) from JDT1 T1 where T1.[RefDate] = [%1])
    set @Dept =  (Select T2.[Name] from OASC T2 where T2.[Name] = [%2])
    set @UnitBusiness = (Select   distinct SUBSTRING(T3.[Segment_0],10,2)  from OACT T3 where ( T3.[Segment_0] = [%3] OR ( 1 = (CASE WHEN [%3]  = 'All'  THEN 1 ELSE 2 END) ) ))
    Select @StartYear,@EndYear,@Dept,@UnitBusiness
    The error is like this
    1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Must specify table to select from.
    2). [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement 'User-Defined Values' (CSHS) (s) could not be prepared.
    Can you help me
    Thanks in advance

Maybe you are looking for