Query to retreive records does not match Frontend values

  • Hi everyone,
      I am using the Query shown below to retrieve records. The value obtained in the column Calcluated_value should be the same as Required_value which is a column I have added here to  the putput for comparing this with the front end screen of the application, how can I modify my query so that it shows the calculated_value to be the same as the front end values which I have shown here in Required_value column.
    Thanks
    IQ

    Query:-
    select distinct top 10000
    AccountSerial,a."Rec ID",
    a."Enc Reading", ,
    STR(CAST(a."Enc Reading" AS DECIMAL)/1000,LEN(a."Enc Reading")+2,3 )  "Calculated Value",
    -- Required_value are the values obtained from Front-end GUI application

    from "Enc Reading Trans" a,
    "Account Enc Xref" b
    where a."Rec ID" = b."Rec ID"
    and CONVERT(date, a."Reading Time") between '2017-01-06' and '2017-01-06'
    and ISNUMERIC("Enc Reading") = 1 and AccountSerial in(101761,125293,505832,662847,183716,143976)
    order by AccountSerial desc

     Output:-

    AccountSerialRec IDEnc ReadingCalculated_valueRequired_Value
    66284750297353000478500    478.500478.500
    66284750297353000479000    479.000479.000
    505832412015190012039   12.0391203.900
    505832412015190012041   12.0411204.100
    18371626985410017771   17.7711777.100
    18371626985410017773   17.7731777.300
    14397650108757000812000    812.000812.000
    12529327755910010455   10.4551045.500
    12529327755910010456   10.4561045.600
    12529327755910010457   10.4571045.700
    101761460121420016030   16.0301603.000
    101761460121420016031   16.0311603.100
    101761460121420016032   16.0321603.200

    c2

  • Just to add some more clarification to my question so people can understand reply me.
    It appears that "Enc Reading" is supposed to represent a number (after all the processing is done), but in the data it is a string.  It also seems that the string is always either seven or nine characters; and when it is nine characters, the last two are always 00.
    If so, calculating the value as   TO_NUMBER( substr("Enc Reading", 1, 7) ) / 10  
    If the nine-character strings don't necessarily end with 00, and instead you want to add two zeros at the end of the seven-digit strings:
    TO_NUMBER( rpad("Enc Reading", 9, '0') ) / 1000

    I want the equivalent functions in SQL server. Obviously the functions shown above are in Oracle. Can someone help me converting TO_NUMBER( rpad("Enc Reading", 9, '0') ) / 1000  into SQL server code ? 

  • Well the equivalent of RPAD in SQL Server would be LEFT(<string> + '000000000', 9)

  • CAST(STUFF([Enc Reading], 7, 0, '.') AS DECIMAL(18,3))

    Drew

    Updated the query, because you want to insert instead of replacing.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Thanks ZZartin ur solution worked for me.
    Drew, Thanks for your solution as well.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply