Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

SQL Server Datatype -> Power Query Fixed decimal number ($)

Hi, Is there a SQL datatype that is recognised by PQ as Fixed decimal number. Decimal(19,4) , MONEY and SMALLMONEY are all recognised as a Decimal number.   The column can be converted using Tabl...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi  BA_Pete ,

    It appears that the Value.NativeQuery does not work as I expected.

     

    Created and populated a small test table.

     

    CREATE TABLE [ref].[TestTable](

           [MoneyDEF] [MONEY] NOT NULL,

           [SmallMoneyDef] [SMALLMONEY] NOT NULL,

           [DecimalDef] [DECIMAL](19, 4) NOT NULL,

           [NumericDef] [NUMERIC](19, 4) NOT NULL,

           [FloatDef] [FLOAT] NOT NULL

    ) ON [PRIMARY]

     

     

     

     

    The following M gives the desired results in that the MONEY/SMALLMONEY columns are imported FIXED DECIMAL the others as FLOAT

     

    let

        Source = Sql.Database("myServer", "myDatabase"),

        ref_TestTable = Source{[Schema="ref",Item="TestTable"]}[Data]

    in

        ref_TestTable

     

    I have been using Value.NativeQuery, which for some reason - as yet to be determined - does not import the MONEY/SMALLMONEY as FIXED DECIMAL all columns are FLOAT

     

    let

      Source = Sql.Databases(Server),

      db = Source{[Name = Database]}[Data],

      TestTable = Value.NativeQuery(

        db,

        "SELECT

                [MoneyDEF],

                [SmallMoneyDef],

                [DecimalDef],

                [NumericDef]

         FROM [ref].[TestTable]",

        null,

        [EnableFolding = true]

      )

    in

        TestTable

     

    The first workaround is not to use Value.NativeQuery but this outcome is a little surprising to me.

     

    Will try and look more into Value.NativeQuery.

     

    Regards,

    B