Query to retrieve values in a particular format

  • Hello,
    I am using the following Table to get data from
    I would like to use a function or code on the last column Cal value such that it matches the values shown in the column Final value
    How can I do this using SQL queries please suggest ?

    Thanks
    IQ

    The code for the table is as follows,
    Table :
    USE [StarDatabase]
    GO

    /****** Object: Table [dbo].[test]  Script Date: 02/26/2018 12:26:39 ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    SET ANSI_PADDING ON
    GO

    CREATE TABLE [dbo].[test](
        [AccountNum] [nvarchar](20) NULL,
        [MTUID] [int] NOT NULL,
        [ReadingTime] [datetime] NOT NULL,
        [data1] [varbinary](100) NULL,
        [New_Value] [varbinary](20) NULL,
        [val] [int] NULL,
        [Cal value] [varchar](8000) NULL
    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING ON
    GO

    Values in the table are as follows: (Book1.xls file attached as well)

    AccountNumMTUIDReadingTimedata1New_ValueValCal ValueFinal_value
    2512504723582712/31/2016 23:350x5C30200x0020305C2109532  2109.53221095.320
    2543734716582612/31/2016 18:290xA4330x000033A413220  13.2201322.000
    2547864736972912/31/2016 2:100x0D0x0000000D130.0130.013
    2924654717780412/31/2016 12:260x3337330x003337333356467  3356.46733564.67
    3101224724270912/31/2016 14:080x80380C0x000C3880800896  800.896800.896
  • IQ1 - Monday, February 26, 2018 10:38 AM

    Hello,
    I am using the following Table to get data from
    I would like to use a function or code on the last column Cal value such that it matches the values shown in the column Final value
    How can I do this using SQL queries please suggest ?

    Thanks
    IQ

    The code for the table is as follows,
    Table :
    USE [StarDatabase]
    GO

    /****** Object: Table [dbo].[test]  Script Date: 02/26/2018 12:26:39 ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    SET ANSI_PADDING ON
    GO

    CREATE TABLE [dbo].[test](
        [AccountNum] [nvarchar](20) NULL,
        [MTUID] [int] NOT NULL,
        [ReadingTime] [datetime] NOT NULL,
        [data1] [varbinary](100) NULL,
        [New_Value] [varbinary](20) NULL,
        [val] [int] NULL,
        [Cal value] [varchar](8000) NULL
    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING ON
    GO

    Values in the table are as follows: (Book1.xls file attached as well)

    AccountNumMTUIDReadingTimedata1New_ValueValCal ValueFinal_value
    2512504723582712/31/2016 23:350x5C30200x0020305C2109532  2109.53221095.320
    2543734716582612/31/2016 18:290xA4330x000033A413220  13.2201322.000
    2547864736972912/31/2016 2:100x0D0x0000000D130.0130.013
    2924654717780412/31/2016 12:260x3337330x003337333356467  3356.46733564.67
    3101224724270912/31/2016 14:080x80380C0x000C3880800896  800.896800.896

    So ... 2109.532 becomes 21095.320 (multiply by 10), yet 13.220 becomes 1322.00 (multiply by 100) and 0.013 stays unchanged.

    What is the (bizarre) calculation logic?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I am not sure but looks like depending on the number of digits in cal value the final value is getting calculated, can someone let me know how to do this ?

  • IQ1 - Monday, February 26, 2018 12:15 PM

    I am not sure but looks like depending on the number of digits in cal value the final value is getting calculated, can someone let me know how to do this ?

    That's not the way things work here. You tell us the logic you require and we will help you implement it.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • IQ1 - Monday, February 26, 2018 12:15 PM

    I am not sure but looks like depending on the number of digits in cal value the final value is getting calculated, can someone let me know how to do this ?

    Until you can get your business users (or your BA person or IT department) to tell you EXACTLY how that is supposed to work, we're no better off than you are.   What I see is totally inconsistent, which makes it utterly impossible to write code for,

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

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

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