Arithmatic conversion error in query

I have a stored procedure for a report . The underlying table has a decimal(18,2) column.
In the Stored Procedure code, the conversion to decimal (12,2) gives an error as one of the records has a value that exceeds (12,2).
I am running this report for a userID that does not have permission to this project (so bad row will not be included in the result).
When running the Stored procedure from query analyser, this row with bad data is not selected based on #TblPermission and SP returns other rows without errors.
The issue is when running the SP from the application, i am getting an arithmatic conversion error.
It appears that the SELECT conversions are happening even before join on the temp table is satisfied.
Shouldnt it filter data based on the join first and then do the conversions (like when run from query analyser) ?
We will be fixing the conversion issue at a later point.
But any ideas/suggestions on how to address this to stop it from erroring when called from the UI ?
CREATE PROCEDURE [dbo].[Test_Report]
@_user varchar(10)
AS
BEGIN
SELECT PID INTO #TblPermission FROM dbo.tbl_permissions(nolock) WHERE userid= @_user
SELECT A.NAME,
 CAST(A.ProjectAmount as decimal(12,2))  Amt -- giving an arithmatic conversion error
FROM TableA A
Join #TblPermission UP on UP.PID= A.PID
WHERE A.ProjectType ='mapped'
end

It appears that the SELECT conversions are happening even before join on the temp table is satisfied.
Shouldnt it filter data based on the join first and then do the conversions (like when run from query analyser) ?
The answer to that question is no.  SQL is allowed to process a query in whatever order it believes will be most efficient.  So it can do the conversion, and later do the WHERE clause.  So you have to write the code so that it is safe if SQL
does that.  One way is to use a case statement to only do the conversion when the value will fit in decimal(12,2), so you could do
SELECT A.NAME,
Case When A.ProjectAmount Between -9999999999.99 And 9999999999.99 Then CAST(A.ProjectAmount as decimal(12,2)) End Amt
FROM TableA A
Join #TblPermission UP on UP.PID= A.PID
WHERE A.ProjectType ='mapped'
That will work on all releases of SQL.
If you are on SQL 2012 or later, you can use the new TRY_CONVERT function which will do conversions without causing errors.  Instead of an error when the valued being converted is invalid, you get NULL.  So that would be
SELECT A.NAME,
TRY_CONVERT(decimal(12,2), A.ProjectAmount) Amt
FROM TableA A
Join #TblPermission UP on UP.PID= A.PID
WHERE A.ProjectType ='mapped'
Tom

Similar Messages

  • Conversion error in Query

    Hi,
    i have an attribute customernumber mapped as Long. My developer now wants to do a query like "select * from xy where customernumber like '567%' ".
    Is it possible to do this with toplink?
    I get conversion errors due to toplink tries to convert 567% to a long value.
    builder.get("customernumber").like("567%")
    -Robert

    The mapping will always try to convert its value passed in to that of the mapped attribute.
    Probably the easiest way to address this is to add another direct query key for the field. If you added one in the mapping editor called customerNumberString to the same database field you could then use:
    builder.get("customerNumberString").like("567%")Doug

  • Most simple query on Event Hub stream (json) constantly gives Data Conversion Errors

    Hello all,
    Been playing with ASA in December and didn't have any issues, my queries kept working and outputted the data as needed.  However, since January, I created a new demo, where I now constantly get Data Conversion errors.  The scenario is described
    below, but I have the following questions:
    Where can I get detailed information on the data conversion errors?  I don't get any point now (not in the operation logs and not in the table storage of my diagnostic storage account)
    What could be wrong in my scenario and could be causing these issues
    The scenario I have implemented is the following:
    My local devices send EventData objects, serialized through Json.Net to an Event Hub with 32 partitions.
    I define my query input as Event Hub Stream and define the data as json/utf8.  I give it the name TelemetryReadings
    Then I write my query as SELECT * FROM TelemetryReadings
    In the output, I create an output on blob with CSV/UTF8 encoding
    After that, I start the job
    The result is an empty blob container (no output written) and tons of data conversion errors in the monitoring graph.  What should I do to get this solved?
    Thanks
    Sam Vanhoutte - CTO Codit - VTS-P BizTalk - Windows Azure Integration: www.integrationcloud.eu

    So, apparently the issue was related to the incoming objects, I had.  I was sending unsupported data types (boolean and Dictionary).  I changed my code to remove these from the json and that worked out well.  There was a change that got deployed
    that (instead of marking the unsupported fields as null, they were throwing an exception).  That's why things worked earlier.
    So, it had to do with the limitation that I mentioned in my earlier comment:
    https://github.com/Azure/azure-content/blob/master/articles/stream-analytics-limitations.md
    Unsupported type conversions result in NULL values
    Any event vales with type conversions not supported in the Data Types section of Azure Stream Analytics Query Language
    Reference will result in a NULL value. In this preview release no error logging is in place for these conversion exceptions.
    I am creating a blog post on this one
    Sam Vanhoutte - CTO Codit - VTS-P BizTalk - Windows Azure Integration: www.integrationcloud.eu

  • Error while impdp: ORA-02374: conversion error loading table

    Hi,
    I am trying to convert the character set from WE8ISO8859P1 to AL32UTF8 using expdp/impdp. for this I first convert WE8ISO8859P1 to WE8MSWIN1252 in source DB to get rid of “lossy” data. I created new database(target) with character set AL32UTF8 and nls_length_semantics = ’CHAR’ and created all the tablespaces as in source DB with auoexend on. I took full export (expdp) of source DB excluding TABLESPACE,STATISTICS,INDEX,CONSTRAINT,REF_CONSTRAINT and imported using impdp to target DB. I found below error in the import log file:
    ORA-02374: conversion error loading table "SCTCVT"."SPRADDR_CVT"
    ORA-26093: input data column size (44) exceeds the maximum input size (40)
    ORA-02372: data for row: CONVERT_STREET_LINE1 : 0X'20202020202020202020202020202020202020202020202020'
    I checked with select query on both DBs with below results.
    source DB:
    04:58:42 SQL> select count(*) from "SCTCVT"."SPRADDR_CVT";
    COUNT(*)
    74553
    target DB:
    04:59:24 SQL> select count(*) from "SCTCVT"."SPRADDR_CVT";
    COUNT(*)
    74552
    please suggest me a solution to this.
    Thanks and Regards.
    Edited by: user12045167 on May 9, 2011 10:39 PM

    Thanks for your update maher.
    09:15:53 SQL> desc "SCTCVT"."SPRADDR_CVT"
    Name Null? Type
    SPRADDR_PIDM NUMBER(8)
    CONVERT_PIDM VARCHAR2(9 CHAR)
    SPRADDR_ATYP_CODE VARCHAR2(2 CHAR)
    CONVERT_ATYP_CODE VARCHAR2(2 CHAR)
    SPRADDR_SEQNO NUMBER(2)
    CONVERT_SEQNO VARCHAR2(2 CHAR)
    SPRADDR_FROM_DATE DATE
    CONVERT_FROM_DATE VARCHAR2(8 CHAR)
    SPRADDR_TO_DATE DATE
    CONVERT_TO_DATE VARCHAR2(8 CHAR)
    SPRADDR_STREET_LINE1 VARCHAR2(30 CHAR)
    CONVERT_STREET_LINE1 VARCHAR2(40 CHAR)
    SPRADDR_STREET_LINE2 VARCHAR2(30 CHAR)
    CONVERT_STREET_LINE2 VARCHAR2(40 CHAR)
    SPRADDR_STREET_LINE3 VARCHAR2(30 CHAR)
    CONVERT_STREET_LINE3 VARCHAR2(40 CHAR)
    SPRADDR_CITY VARCHAR2(20 CHAR)
    CONVERT_CITY VARCHAR2(25 CHAR)
    SPRADDR_STAT_CODE VARCHAR2(3 CHAR)
    CONVERT_STAT_CODE VARCHAR2(25 CHAR)
    SPRADDR_ZIP VARCHAR2(10 CHAR)
    CONVERT_ZIP VARCHAR2(15 CHAR)
    SPRADDR_CNTY_CODE VARCHAR2(5 CHAR)
    CONVERT_CNTY_CODE VARCHAR2(5 CHAR)
    SPRADDR_NATN_CODE VARCHAR2(5 CHAR)
    CONVERT_NATN_CODE VARCHAR2(5 CHAR)
    SPRADDR_PHONE_AREA VARCHAR2(3 CHAR)
    CONVERT_PHONE_AREA VARCHAR2(3 CHAR)
    SPRADDR_PHONE_NUMBER VARCHAR2(7 CHAR)
    CONVERT_PHONE_NUMBER VARCHAR2(7 CHAR)
    SPRADDR_PHONE_EXT VARCHAR2(4 CHAR)
    CONVERT_PHONE_EXT VARCHAR2(4 CHAR)
    SPRADDR_STATUS_IND VARCHAR2(1 CHAR)
    CONVERT_STATUS_IND VARCHAR2(1 CHAR)
    SPRADDR_ACTIVITY_DATE DATE
    CONVERT_ACTIVITY_DATE VARCHAR2(8 CHAR)
    SPRADDR_USER VARCHAR2(30 CHAR)
    CONVERT_USER VARCHAR2(30 CHAR)
    SPRADDR_ASRC_CODE VARCHAR2(4 CHAR)
    CONVERT_ASRC_CODE VARCHAR2(4 CHAR)
    SPRADDR_DELIVERY_POINT NUMBER(2)
    CONVERT_DELIVERY_POINT VARCHAR2(2 CHAR)
    SPRADDR_CORRECTION_DIGIT NUMBER(1)
    CONVERT_CORRECTION_DIGIT VARCHAR2(1 CHAR)
    SPRADDR_CARRIER_ROUTE VARCHAR2(4 CHAR)
    CONVERT_CARRIER_ROUTE VARCHAR2(4 CHAR)
    SPRADDR_GST_TAX_ID VARCHAR2(15 CHAR)
    CONVERT_GST_TAX_ID VARCHAR2(15 CHAR)
    SPRADDR_REVIEWED_IND VARCHAR2(1 CHAR)
    CONVERT_REVIEWED_IND VARCHAR2(1 CHAR)
    SPRADDR_REVIEWED_USER VARCHAR2(30 CHAR)
    CONVERT_REVIEWED_USER VARCHAR2(30 CHAR)
    SPRADDR_DATA_ORIGIN VARCHAR2(30 CHAR)
    CONVERT_DATA_ORIGIN VARCHAR2(30 CHAR)
    SPRADDR_CVT_RECORD_ID NUMBER(8)
    SPRADDR_CVT_STATUS VARCHAR2(1 CHAR)
    SPRADDR_CVT_JOB_ID NUMBER(8)
    so here we can see its value is 40 (CONVERT_STREET_LINE1 VARCHAR2(40 CHAR)).
    shall i go ahead altering the column?

  • Data Conversion Errors for the last week

    We've been running a simple Stream Analytics job for little over a month now with a very light workload. Input is Event hub and output SQL Server. We noticed today that we haven't received anything into SQL Server since 2014-12-08 (we don't receive events
    every day so we only know that everything still worked on the 8th of December), so we checked the job's logs. It seems that job is failing to process all the messages: The value of "Data Conversion Errors" is high.
    I wonder what could have happened? We haven't touched the client since we started the job so it's still sending the messages in same format. And we haven't touched the job's query either.
    Has there been an update to either to Stream Analytics or to Events Hub which could cause the issue we're seeing?

    I've followed word for word the TollApp Instructions (except the thing with NamespaceType "Messaging" that has been added to New-AzureSBNamespace).
    I have 0 line in output, and this is the service log:
    Correlation ID:
    e94f5b9e-d755-4160-b49e-c8225ceced0c
    Error:
    Message:
    After deserialization, 0 rows have been found. Possible reasons could be a missing header or malformed CSV input.
    Message Time:
    2015-01-21 10:35:15Z
    Microsoft.Resources/EventNameV2:
    sharedNode92F920DE-290E-4B4C-861A-F85A4EC01D82.entrystream_0_c76f7247_25b7_4ca6_a3b6_c7bf192ba44a#0.output
    Microsoft.Resources/Operation:
    Information
    Microsoft.Resources/ResourceUri:
    /subscriptions/eb880f80-0028-49db-b956-464f8439270f/resourceGroups/StreamAnalytics-Default-West-Europe/providers/Microsoft.StreamAnalytics/streamingjobs/TollData
    Type:
    CsvParserError
    Then I stopped the job, and connected to the event hub with a console app and received that:
    Message received. Partition: '11', Data: 'TollId,EntryTime,LicensePlate,State,Make,Model,VehicleType,VehicleWeight,Toll,Tag
    85,21/01/2015 10:24:56,QBQ 1188,OR,Toyota,4x4,1,0,4,361203677
    Message received. Partition: '11', Data: 'TollId,EntryTime,LicensePlate,State,Make,Model,VehicleType,VehicleWeight,Toll,Tag
    33,21/01/2015 10:25:42,BSE 3166,PA,Toyota,Rav4,1,0,6,603558073
    Message received. Partition: '11', Data: 'TollId,EntryTime,LiMessage received. Partition: '10', Data: 'TollId,EntryTime,LicensePlate,State,Make,Model,VehicleType,VehicleWeight,Toll,Tag
    59,21/01/2015 10:23:59,AXD 1469,CA,Toyota,Camry,1,0,6,150568526
    Message received. Partition: '10', Data: 'TollId,EntryTime,LicensePlate,State,Make,Model,VehicleType,VehicleWeight,Toll,Tag
    25,21/01/2015 10:24:17,OLW 6671,NJ,Honda,Civic,1,0,5,729503344
    Message received. Partition: '10', Data: 'TollId,EntryTime,LicensePlate,State,Make,Model,VehicleType,VehicleWeight,Toll,Tag
    51,21/01/2015 10:24:23,LTV 6699,CA,Honda,CRV,1,0,5,169341662
    Note the bug on the 3rd message. In my opinion it's unrelated, it could be the writeline that can't keep up with the stream in the console application. And at worst it's in the stream, but then I should see at least some lines in output for the correctly
    formatted messages.

  • Error named like "CONVERSION ERROR"

    I am creating one Module Pool Program with the Screen Painter. There is total 10 Tab Strips used in the Screen Painter.
    When I select the Last Tab, I get the Error with the message " CONVERSION ERROR"
    Can you guide me why this error can occurs?

    Hi,
    Check whether you are entering false values in a field which is not belong to that type.
    For example, if you enter characteristic value into a numeric field and doing arithmatic operations.
    CONVERSION ERROR occurs in this case.
    Please check for above.
    Regards,
    Rajesh

  • 5200:Error Executing Query

    Hi,
    I am getting below error while running a report in FR.
    5200:Error Executing Query:
    Could you please let me know what is the problem and how to resolve it.
    Thanks,

    Hi,
    This might be due to corrupt POV this can be resolved by just deleting POV for the use and again setting it up.
    Regards,
    Gyan

  • Open PO LSMW Quantity conversion error in net price calculation

    Hi gurus,
    I encountered an error as I was tring to upload purchase orders - "Quantity conversion error in net price calculation". What does this mean and how do I fix this?
    Please help
    Thanks

    Hi Jürgen,
    Where in the Material Master can I find the conversion ratio between both units?
    Also, I am trying to upload POs for Spare Parts and that's when I get the error. But when I try to use other materials like FGs, everything is ok. I can proceed with the upload without any problem
    Please help

  • How to custom a conversion error in JSF page in JDeveloper

    According to the book "Core JavaServer Faces" p213 (fifth edition), if I add the following line to messages.properties file, and specifiy it in the faces-config.xml and .jsp file, then the displayed conversion error message should be my tailored one instead of the default. However, I still get the default error message. Besides, I didn't find "CONVERSION" variable in UIInput class. Is the book wrong? And what's the correct way?
    javax.faces.component.UIInput.CONVERSION=Please correct your input

    I didn't choose any special in JDeveloper IDE. I just selected "new" to create a file called "message.properties" and put the line there. I didn't specify converters excepts declaring the type in the Jave Beans. I guess the converting is done by the JSF framework automatically. It must be a JSF converter since I created the page as a JSF page.

  • Error in Query Execution : SQL Error: 1110

    Dear Experts,
         We did the system copy from production to Sandbox system. Executing one query got terminated with the following error.
         Error SQL Error: 1110
         Abort System error in program SAPLRRK0 and form RSRDR;SRRK0F30-01-
         I copy this query to the new one and remove all the filter. It works!!!
         Any suggestion on this issue?
    Regards

    Hi,
    check these threads
    BEx query error
    BEx Query Error
    Regards
    harikrishna N

  • Error  in query definition

    Hi all,
    I am getting the following error when accessing HR payroll quires
    "Formal error in query definition ( DIM <-> from[NAV]) ?
    Can any body help me ?
    KK

    I am getting the same error. Could you pls post the solution. I am on the following level (from the error message.
    BI Java Release: 7 - Patch level: 0000000011 - Description: BI Web Applications Java - Additional info: - Production mode: true
    BI ABAP Release: 700 - Patch level: 0012 - Description: SAP NetWeaver BI 7.0 (SAP_BW) - Additional info: - Production mode: true
    Java Virtual Machine IBM J9 VM - IBM Corporation - 2.3
    Operating System AIX - ppc64 - 5.3
    I searched the OSS and found a note 1001621 which said apply support package: SAP_BW_VIRTUAL_COMP - Rel 700 - Pkg name SAPK70012NVCBWTECH
    But, our basis guys came back with the reply that the solution suggested in OSS note is for SAPKW70011, but our system is already on SAPKW70012. So, this note cannot be applied.
    Any help would be appreciated.

  • Error in query: [Microsoft][SQL Server Native Client 10.0][SQL Server]Must specify table to select from. '' (SWEI)

    Hi All
    below query giving me error in query generator but working well in Sql server.
    error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Must specify table to select from. '' (SWEI)
    Select
    T1.U_grp01 As 'BA',T3.DocDate As 'Posting Date',Month(T3.DocDate) As 'PostMonth',Year(T3.DocDate) As 'PostYear',
    'AR Invoice' As 'Type',T3.DocNum As 'Doc No',T3.CardCode As 'Cust. Code',T3.CardName As 'Cust. Name',T5.SlpName As 'Sale Emp. Name',
    T4.IndustryC As 'Channel Type',T6.CityB As 'BillToCity',T7.Name As 'BillToState',T6.CityS As 'ShipToCity',T8.Name As 'ShipToState',
    T4.U_Une_Zone As 'Zone',
    T2.ItmsGrpNam As 'L1',T0.LineNum As 'Row No',T0.ItemCode As 'ItemCode',T0.Dscription As 'Item Name',t0.whscode,
    T0.Quantity As 'Quantity',T0.StockPrice As 'COGS Price',IsNull(Sum(T0.Quantity * T0.StockPrice),0) As 'COGS Value',T0.VatSum As 'Tax Amount',
    IsNull((Case When T3.DocType='I' Then (Case  When T0.Currency = 'INR' Then T0.PriceBefDi Else (T0.PriceBefDi * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
    IsNull((Case When T3.DocType='I' Then (Case  When T0.Currency = 'INR' Then T0.INMPrice Else (T0.INMPrice * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
    IsNull((Case When T3.DocType='I' Then (Case  When T0.Currency = 'INR' Then Sum(T0.Quantity * T0.INMPrice) Else Sum(T0.Quantity * T0.INMPrice * T0.Rate) End) Else T0.LineTotal End) ,0) As 'Sales Value',t9.linetotal as 'Freight',
    T3.DocType As 'DocType',
    (SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
    FROM INV4
    WHERE INV4.StaType = -90
    AND INV4.DocEntry = T3.DocEntry
    AND INV4.LineNum = T0.LineNum) AS 'BED',
    (SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
    FROM INV4
    WHERE INV4.StaType = -60
    AND INV4.DocEntry = T3.DocEntry
    AND INV4.LineNum = T0.LineNum) AS 'Cess',
    (SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
    FROM INV4
    WHERE INV4.StaType = 9
    AND INV4.DocEntry = T3.DocEntry
    AND INV4.LineNum = T0.LineNum) AS 'HeCess',
    (SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
    FROM INV4
    WHERE (INV4.StaType = 1 or inv4.staType = 8)
    AND INV4.DocEntry = T3.DocEntry
    AND INV4.LineNum = T0.LineNum) AS 'VAT',
    (SELECT DISTINCT ISNULL (SUM(INV4.TaxSum),0)
    FROM INV4
    WHERE INV4.StaType = 8
    AND INV4.DocEntry = T3.DocEntry
    AND INV4.LineNum = T0.LineNum) AS 'CST'
    From INV1 T0
    Left Join OITM T1 On T1.ItemCode=T0.ItemCode
    Left Join OITB T2 On T2.ItmsGrpCod=T1.ItmsGrpCod
    Left Join OINV T3 On T3.DocEntry=T0.DocEntry
    Left Join OCRD T4 On T4.CardCode=T3.CardCode
    Left Join OSLP T5 On T5.SlpCode=T4.SlpCode
    Left Join INV12 T6 On T6.DocEntry=T0.DocEntry
    Left Join OCST T7 On T7.Code=T6.StateB and T7.Country='IN'
    Left Join OCST T8 On T8.Code=T6.StateS and T8.Country='IN'
    left join inv3 t9 on t9.docentry = t3.docentry
    WHERE T3.[DocDate] >= [%0] and T3.[DocDate] <= [%1] and t3.U_UNE_GCAT = '2'
    Group By T1.U_grp01,T3.DocEntry,T3.DocNum,T3.DocDate,T0.LineNum,T3.CardCode,T3.CardName,T5.SlpName,T4.IndustryC,T4.U_Une_Zone,
    T6.CityB,T7.Name,T6.CityS,T8.Name,T0.VatSum,T0.Currency,T0.Rate,T3.DocType,T0.Price,T0.LineTotal,
    T2.ItmsGrpNam,T0.ItemCode,T0.Dscription,T0.StockPrice,T0.INMPrice,T0.PriceBefDi,T0.Quantity,t9.linetotal,t0.WhsCode
    Union All
    Select
    T1.U_grp01 As 'BA',T3.DocDate As 'Posting Date',Month(T3.DocDate) As 'PostMonth',Year(T3.DocDate) As 'PostYear',
    'AR Invoice' As 'Type',T3.DocNum As 'Doc No',T3.CardCode As 'Cust. Code',T3.CardName As 'Cust. Name',T5.SlpName As 'Sale Emp. Name',
    T4.IndustryC As 'Channel Type',T6.CityB As 'BillToCity',T7.Name As 'BillToState',T6.CityS As 'ShipToCity',T8.Name As 'ShipToState',
    T4.U_Une_Zone As 'Zone',
    T2.ItmsGrpNam As 'L1',T0.LineNum As 'Row No',T0.ItemCode As 'ItemCode',T0.Dscription As 'Item Name',t0.whscode,
    T0.Quantity As 'Quantity',T0.StockPrice As 'COGS Price',IsNull(Sum(T0.Quantity * T0.StockPrice),0) As 'COGS Value',T0.VatSum As 'Tax Amount',
    IsNull((Case When T3.DocType='I' Then (Case  When T0.Currency = 'INR' Then T0.PriceBefDi Else (T0.PriceBefDi * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
    IsNull((Case When T3.DocType='I' Then (Case  When T0.Currency = 'INR' Then T0.INMPrice Else (T0.INMPrice * T0.Rate) End) Else T0.Price End) ,0) As 'Sales Price',
    IsNull((Case When T3.DocType='I' Then (Case  When T0.Currency = 'INR' Then Sum(T0.Quantity * T0.INMPrice) Else Sum(T0.Quantity * T0.INMPrice * T0.Rate) End) Else T0.LineTotal End) ,0) As 'Sales Value',t9.linetotal as 'Freight',
    T3.DocType As 'DocType',
    (SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
    FROM rin4
    WHERE rin4.StaType = -90
    AND rin4.DocEntry = T3.DocEntry
    AND rin4.LineNum = T0.LineNum) AS 'BED',
    (SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
    FROM rin4
    WHERE rin4.StaType = -60
    AND rin4.DocEntry = T3.DocEntry
    AND rin4.LineNum = T0.LineNum) AS 'Cess',
    (SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
    FROM rin4
    WHERE rin4.StaType = 9
    AND rin4.DocEntry = T3.DocEntry
    AND rin4.LineNum = T0.LineNum) AS 'HeCess',
    (SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
    FROM rin4
    WHERE (rin4.StaType = 1 or rin4.staType = 8)
    AND rin4.DocEntry = T3.DocEntry
    AND rin4.LineNum = T0.LineNum) AS 'VAT',
    (SELECT DISTINCT ISNULL (SUM(rin4.TaxSum),0)
    FROM rin4
    WHERE rin4.StaType = 8
    AND rin4.DocEntry = T3.DocEntry
    AND rin4.LineNum = T0.LineNum) AS 'CST'
    From rin1 T0
    Left Join OITM T1 On T1.ItemCode=T0.ItemCode
    Left Join OITB T2 On T2.ItmsGrpCod=T1.ItmsGrpCod
    Left Join Orin T3 On T3.DocEntry=T0.DocEntry
    Left Join OCRD T4 On T4.CardCode=T3.CardCode
    Left Join OSLP T5 On T5.SlpCode=T4.SlpCode
    Left Join rin12 T6 On T6.DocEntry=T0.DocEntry
    Left Join OCST T7 On T7.Code=T6.StateB and T7.Country='IN'
    Left Join OCST T8 On T8.Code=T6.StateS and T8.Country='IN'
    left join rin3 t9 on t9.docentry = t3.docentry
    WHERE T3.[DocDate] >= [%0] and T3.[DocDate] <= [%1] and t3.U_UNE_GCAT = '2'
    Group By T1.U_grp01,T3.DocEntry,T3.DocNum,T3.DocDate,T0.LineNum,T3.CardCode,T3.CardName,T5.SlpName,T4.IndustryC,T4.U_Une_Zone,
    T6.CityB,T7.Name,T6.CityS,T8.Name,T0.VatSum,T0.Currency,T0.Rate,T3.DocType,T0.Price,T0.LineTotal,
    T2.ItmsGrpNam,T0.ItemCode,T0.Dscription,T0.StockPrice,T0.INMPrice,T0.PriceBefDi,T0.Quantity,t9.linetotal,t0.WhsCode
    Thanks in Advance

    Hi deepak..
    try this
    /* SELECT FROM OSRT P1 */
    DECLARE @FROM AS DATE
    /* WHERE */
    SET @FROM = /* P1.FromDate */ '[%1]'
    /* SELECT FROM OSRT P2 */
    DECLARE @TO AS DATE
    /* WHERE */
    SET @TO = /* P2.ToDate */ '[%2]';
    SELECT T1.U_grp01 AS 'BA',
           T3.DocDate AS 'Posting Date',
           MONTH(T3.DocDate) AS 'PostMonth',
           YEAR(T3.DocDate) AS 'PostYear',
           'AR Invoice' AS 'Type',
           T3.DocNum AS 'Doc No',
           T3.CardCode AS 'Cust. Code',
           T3.CardName AS 'Cust. Name',
           T5.SlpName AS 'Sale Emp. Name',
           T4.IndustryC AS 'Channel Type',
           T6.CityB AS 'BillToCity',
           T7.Name AS 'BillToState',
           T6.CityS AS 'ShipToCity',
           T8.Name AS 'ShipToState',
           T4.U_Une_Zone AS 'Zone',
           T2.ItmsGrpNam AS 'L1',
           T0.LineNum AS 'Row No',
           T0.ItemCode AS 'ItemCode',
           T0.Dscription AS 'Item Name',
           t0.whscode,
           T0.Quantity AS 'Quantity',
           T0.StockPrice AS 'COGS Price',
           ISNULL(SUM(T0.Quantity * T0.StockPrice), 0) AS 'COGS Value',
           T0.VatSum AS 'Tax Amount',
           ISNULL(
                   CASE
                        WHEN T3.DocType = 'I' THEN (
                                 CASE
                                      WHEN T0.Currency = 'INR' THEN T0.PriceBefDi
                                      ELSE (T0.PriceBefDi * T0.Rate)
                                 END
                        ELSE T0.Price
                   END
               0
           ) AS 'Sales Price',
           ISNULL(
                   CASE
                        WHEN T3.DocType = 'I' THEN (
                                 CASE
                                      WHEN T0.Currency = 'INR' THEN T0.INMPrice
                                      ELSE (T0.INMPrice * T0.Rate)
                                 END
                        ELSE T0.Price
                   END
               0
           ) AS 'Sales Price',
           ISNULL(
                   CASE
                        WHEN T3.DocType = 'I' THEN (
                                 CASE
                                      WHEN T0.Currency = 'INR' THEN SUM(T0.Quantity * T0.INMPrice)
                                      ELSE SUM(T0.Quantity * T0.INMPrice * T0.Rate)
                                 END
                        ELSE T0.LineTotal
                   END
               0
           ) AS 'Sales Value',
           t9.linetotal AS 'Freight',
           T3.DocType AS 'DocType',
               SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
               FROM   INV4
               WHERE  INV4.StaType = -90
                      AND INV4.DocEntry = T3.DocEntry
                      AND INV4.LineNum = T0.LineNum
           ) AS 'BED',
               SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
               FROM   INV4
               WHERE  INV4.StaType = -60
                      AND INV4.DocEntry = T3.DocEntry
                      AND INV4.LineNum = T0.LineNum
           ) AS 'Cess',
               SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
               FROM   INV4
               WHERE  INV4.StaType = 9
                      AND INV4.DocEntry = T3.DocEntry
                      AND INV4.LineNum = T0.LineNum
           ) AS 'HeCess',
               SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
               FROM   INV4
               WHERE  (INV4.StaType = 1 OR inv4.staType = 8)
                      AND INV4.DocEntry = T3.DocEntry
                      AND INV4.LineNum = T0.LineNum
           ) AS 'VAT',
               SELECT DISTINCT ISNULL(SUM(INV4.TaxSum), 0)
               FROM   INV4
               WHERE  INV4.StaType = 8
                      AND INV4.DocEntry = T3.DocEntry
                      AND INV4.LineNum = T0.LineNum
           ) AS 'CST'
    FROM   INV1 T0
           LEFT JOIN OITM T1
                ON  T1.ItemCode = T0.ItemCode
           LEFT JOIN OITB T2
                ON  T2.ItmsGrpCod = T1.ItmsGrpCod
           LEFT JOIN OINV T3
                ON  T3.DocEntry = T0.DocEntry
           LEFT JOIN OCRD T4
                ON  T4.CardCode = T3.CardCode
           LEFT JOIN OSLP T5
                ON  T5.SlpCode = T4.SlpCode
           LEFT JOIN INV12 T6
                ON  T6.DocEntry = T0.DocEntry
           LEFT JOIN OCST T7
                ON  T7.Code = T6.StateB
                AND T7.Country = 'IN'
           LEFT JOIN OCST T8
                ON  T8.Code = T6.StateS
                AND T8.Country = 'IN'
           LEFT JOIN inv3 t9
                ON  t9.docentry = t3.docentry
    WHERE  T3.[DocDate] >= @FROM
           AND T3.[DocDate] <= @TO
           AND t3.U_UNE_GCAT = '2'
    GROUP BY
           T1.U_grp01,
           T3.DocEntry,
           T3.DocNum,
           T3.DocDate,
           T0.LineNum,
           T3.CardCode,
           T3.CardName,
           T5.SlpName,
           T4.IndustryC,
           T4.U_Une_Zone,
           T6.CityB,
           T7.Name,
           T6.CityS,
           T8.Name,
           T0.VatSum,
           T0.Currency,
           T0.Rate,
           T3.DocType,
           T0.Price,
           T0.LineTotal,
           T2.ItmsGrpNam,
           T0.ItemCode,
           T0.Dscription,
           T0.StockPrice,
           T0.INMPrice,
           T0.PriceBefDi,
           T0.Quantity,
           t9.linetotal,
           t0.WhsCode
    UNION ALL
    SELECT T1.U_grp01 AS 'BA',
           T3.DocDate AS 'Posting Date',
           MONTH(T3.DocDate) AS 'PostMonth',
           YEAR(T3.DocDate) AS 'PostYear',
           'AR Invoice' AS 'Type',
           T3.DocNum AS 'Doc No',
           T3.CardCode AS 'Cust. Code',
           T3.CardName AS 'Cust. Name',
           T5.SlpName AS 'Sale Emp. Name',
           T4.IndustryC AS 'Channel Type',
           T6.CityB AS 'BillToCity',
           T7.Name AS 'BillToState',
           T6.CityS AS 'ShipToCity',
           T8.Name AS 'ShipToState',
           T4.U_Une_Zone AS 'Zone',
           T2.ItmsGrpNam AS 'L1',
           T0.LineNum AS 'Row No',
           T0.ItemCode AS 'ItemCode',
           T0.Dscription AS 'Item Name',
           t0.whscode,
           T0.Quantity AS 'Quantity',
           T0.StockPrice AS 'COGS Price',
           ISNULL(SUM(T0.Quantity * T0.StockPrice), 0) AS 'COGS Value',
           T0.VatSum AS 'Tax Amount',
           ISNULL(
                   CASE
                        WHEN T3.DocType = 'I' THEN (
                                 CASE
                                      WHEN T0.Currency = 'INR' THEN T0.PriceBefDi
                                      ELSE (T0.PriceBefDi * T0.Rate)
                                 END
                        ELSE T0.Price
                   END
               0
           ) AS 'Sales Price',
           ISNULL(
                   CASE
                        WHEN T3.DocType = 'I' THEN (
                                 CASE
                                      WHEN T0.Currency = 'INR' THEN T0.INMPrice
                                      ELSE (T0.INMPrice * T0.Rate)
                                 END
                        ELSE T0.Price
                   END
               0
           ) AS 'Sales Price',
           ISNULL(
                   CASE
                        WHEN T3.DocType = 'I' THEN (
                                 CASE
                                      WHEN T0.Currency = 'INR' THEN SUM(T0.Quantity * T0.INMPrice)
                                      ELSE SUM(T0.Quantity * T0.INMPrice * T0.Rate)
                                 END
                        ELSE T0.LineTotal
                   END
               0
           ) AS 'Sales Value',
           t9.linetotal AS 'Freight',
           T3.DocType AS 'DocType',
               SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
               FROM   rin4
               WHERE  rin4.StaType = -90
                      AND rin4.DocEntry = T3.DocEntry
                      AND rin4.LineNum = T0.LineNum
           ) AS 'BED',
               SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
               FROM   rin4
               WHERE  rin4.StaType = -60
                      AND rin4.DocEntry = T3.DocEntry
                      AND rin4.LineNum = T0.LineNum
           ) AS 'Cess',
               SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
               FROM   rin4
               WHERE  rin4.StaType = 9
                      AND rin4.DocEntry = T3.DocEntry
                      AND rin4.LineNum = T0.LineNum
           ) AS 'HeCess',
               SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
               FROM   rin4
               WHERE  (rin4.StaType = 1 OR rin4.staType = 8)
                      AND rin4.DocEntry = T3.DocEntry
                      AND rin4.LineNum = T0.LineNum
           ) AS 'VAT',
               SELECT DISTINCT ISNULL(SUM(rin4.TaxSum), 0)
               FROM   rin4
               WHERE  rin4.StaType = 8
                      AND rin4.DocEntry = T3.DocEntry
                      AND rin4.LineNum = T0.LineNum
           ) AS 'CST'
    FROM   rin1 T0
           LEFT JOIN OITM T1
                ON  T1.ItemCode = T0.ItemCode
           LEFT JOIN OITB T2
                ON  T2.ItmsGrpCod = T1.ItmsGrpCod
           LEFT JOIN [dbo].[Orin] T3
                ON  T3.DocEntry = T0.DocEntry
           LEFT JOIN OCRD T4
                ON  T4.CardCode = T3.CardCode
           LEFT JOIN OSLP T5
                ON  T5.SlpCode = T4.SlpCode
           LEFT JOIN rin12 T6
                ON  T6.DocEntry = T0.DocEntry
           LEFT JOIN OCST T7
                ON  T7.Code = T6.StateB
                AND T7.Country = 'IN'
           LEFT JOIN OCST T8
                ON  T8.Code = T6.StateS
                AND T8.Country = 'IN'
           LEFT JOIN rin3 t9
                ON  t9.docentry = t3.docentry
    WHERE  T3.[DocDate] >= @FROM
           AND T3.[DocDate] <= @TO
           AND t3.U_UNE_GCAT = '2'
    GROUP BY
           T1.U_grp01,
           T3.DocEntry,
           T3.DocNum,
           T3.DocDate,
           T0.LineNum,
           T3.CardCode,
           T3.CardName,
           T5.SlpName,
           T4.IndustryC,
           T4.U_Une_Zone,
           T6.CityB,
           T7.Name,
           T6.CityS,
           T8.Name,
           T0.VatSum,
           T0.Currency,
           T0.Rate,
           T3.DocType,
           T0.Price,
           T0.LineTotal,
           T2.ItmsGrpNam,
           T0.ItemCode,
           T0.Dscription,
           T0.StockPrice,
           T0.INMPrice,
           T0.PriceBefDi,
           T0.Quantity,
           t9.linetotal,
           t0.WhsCode
    rgds
    Kennedy

  • Error in Query (EXCEPT)

    Dear Experts,
    I Have Error in query
    My Query Such as:
    Select TransNum from Oinm where transType=310000001
    Except
    Select Docnum from [dbo].[Opn_Stock] where U_ TransTypeStk=310000001
    Show Error: Browse mode is invalid for statements containing a UNION, INTERSECT and EXCEPT operator.
    Note: This query smoothly run in Sql 2005 but throw Error in SAP while execute in sap query generator.
    Regards,
    Sumeet Vaity

    The SBO generally inserts a for browse line at the end of the query. But not allways! E.g. probably your query would work if you refrase it in such a way:
    Select TransNum from Oinm where transType=310000001
    Except --union
    Select Docnum from dbo.Opn_Stock where U_ TransTypeStk=310000001
    That is it does not insert this line in case of a union, even in the comment part!

  • An error occurred querying a data source - with REST services

    Hi,
    I have a SharePoint 2013 form library library with an info-path form. I need to get the logged in user's 'Display Name' on my form load automatically.
    I used REST service to fetch the current user details. In the preview mode of the form, its showing the right name. But when I publish this form to library I am getting the following error.
    REST Service --> http://site url/_api/SP.UserProfiles.PeopleManager/GetMyProperties
    Please help me to resolve this issue.
    Thanks in advance for your time and reply :)

    Hi,
    According to your post, my understanding is that an error occurred querying a data source with REST services.
    It is defiantly permission issue with GetUserProfileByName service
    and could be many reasons of this problem. You first try with UDCX file and make sure that UPS is running.
    Here are some similar threads for your reference:
    http://social.technet.microsoft.com/Forums/en-US/b8c668ea-7511-4657-a1a8-08fb4a6bd53d/info-path-an-error-occurred-querying-a-data-source?forum=sharepointcustomizationprevious
    http://social.technet.microsoft.com/Forums/en-US/46866ac2-da09-4340-a86a-af72cbb2c8d7/info-path-an-error-occurred-querying-a-data-source-?forum=sharepointcustomization
    http://blogs.msdn.com/b/russmax/archive/2012/08/17/want-to-call-sharepoint-2010-web-services-within-browser-based-infopath-2010-forms.aspx
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Error occurred querying a data source in office 365.

    I have created a simple infopath form and in one of my dropdown box  i am receiving the REST services. 
    when i run the infopath form 2013 in preview it was running good but when i upload it on to office 365 cloud it's showing me error. i had converted the services into UDL and save it on Data connection Library and it's approved.
    Warning
    Click OK to resume filling out the form. You may want to check your form data for errors.
    The entry has been added to the Windows event log of the server.
    log ID:5566
    Correlation ID:feb08a9c-9d47-30f5-5d89-60340242d6d1.

    Hi,
    According to your post, my understanding is that you got error when querying a data source in office 365.
    Per my knowleadge, we cannot connect to SharePoint Web Services from InfoPath Forms within SharePoint Online.
    Loopback protection is enabled on the SharePoint Online environment and will block calls to SOAP and REST from InfoPath Form Services.
    For more information, you can refer to:
    Error message when you connect an InfoPath form to a SharePoint Online web service: "An error occurred while connecting to a Web Service"
    As a workaround, to look up data for some dropdowns from several external REST Web Services, we need to have a Data Connection library in your Site Collection in which to store the UDCX files.
    The steps seem to be:
    Create a Data Connection Library in your Site Collection
    In the InfoPath ribbon, go to Data, then Data Connections. Your existing data connections should be listed.
    Choose the data connection which is hosted on a different domain.
    Clink the
    Convert to  Connection File… button
    In the location selector, specify the path to the Data Connection Library you created above.
    Leave the
    Relative to  site collection (recommended) radio button selected.
    Click OK
    Here is a great blog for your reference:
    InfoPath 2013 Forms on Office365 with External REST DataSources
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

Maybe you are looking for

  • Extra entries in the exchange rate difference.

    Hi Experts, when posting exchange differences between payment posted on our vendor account & amount debited by the bank. Itm PK Account   Alt. A Assignment       Acct short text Tx     Amount Curr.    Amount in LC LCur Text   1 50 3028120   666880 00

  • GUI_UPLOAD &  GUI_DOWNLOAD

    Hi Could anyone please explain me kind of inputs that I need to give to this Function Module. I want to import one excel file and need to do some processing on it and replace original excel file by new one. Can i Use above mentioned Function Modules

  • Unable to Preserve Users & Network Settings

    I am trying to go back to Tiger from Leopard on my iMac G4 (17" 1 GHz). However, when I choose Archive and Install, the option to Preserve Users & Network settings is dimmed out and I cannot select it. First time I have encountered this. Any ideas as

  • BI releases through time

    Hi there, Does someone have a overview (preferable in a picture) of all BW releases on a time frame? This would be helpful to create my view on this. I searched service.sap.com\bi, but could not find it. Your help would be appreciated.

  • Smart Album to isolate iPhone Photos only?

    I have had each version of the iPhone since it's initial release several years back. I want to know if it's possible to create a smart album to group just my iPhone photos (not movies), regardless of which version of the iPhone shot the image. Is thi