Convert decimal to binary

by Amol 21. February 2011 19:20

CREATE FUNCTION [dbo].[GetBinary] (@DecimalNumber BIGINT)

RETURNS VARCHAR(8000)

AS

BEGIN

   

    DECLARE @BinaryNumber VARCHAR(MAX);

   

    WITH cte (Id, Reminder) 

    AS

    (

    SELECT

         @DecimalNumber / 2 AS Id

        ,@DecimalNumber % 2 AS Reminder

    UNION ALL

    SELECT

         cte.id / 2

        ,cte.id % 2 AS Reminder

    FROM cte

    WHERE cte.Id > 0

    )

    SELECT @BinaryNumber = COALESCE(@BinaryNumber, '') + CAST(Reminder AS CHAR(1))

    FROM cte

    ORDER BY id

   

    RETURN (@BinaryNumber)

 

END

Tags:

SQL Server Scripts

Convert binary to decimal

by Amol 21. February 2011 19:18

CREATE FUNCTION [dbo].[GetDecimal] (@BinaryNumber BIGINT)

RETURNS BIGINT

AS

BEGIN

   

    DECLARE  @DecimalNumber BIGINT

            ,@Divider BIGINT

            ,@BinaryNumberLength INT

           

    SET @BinaryNumberLength = LEN(@BinaryNumber) - 1

    SET @Divider = '1' + REPLICATE('0', @BinaryNumberLength);

      

    WITH cte (Id, Divider, lvl) 

    AS

    (

    SELECT 

         @BinaryNumber / @Divider AS Id

        ,@Divider/10 AS Divider

        ,@BinaryNumberLength AS lvl

    UNION ALL

    SELECT

         @BinaryNumber / Divider AS Id

        ,Divider/10 AS Divider

        ,lvl - 1

    FROM cte

    WHERE Divider > 0

    )

    SELECT @DecimalNumber = SUM(RIGHT(Id, 1) * POWER(2, Lvl))

    FROM cte

       

    RETURN (@DecimalNumber)

 

END


Tags:

SQL Server Scripts

Physical Data Model

by Amol 20. February 2011 10:57

Physical Data Modeling:

The next step after Logical Data Model is to generate Physical Data Model. Physical data model is generated from the approved Logical Data Model.

Logical and Physical data model looks same but having some major differences between them. Such as Physical Data Model includes all required database objects like tables, columns, Keys, relationships, database properties for the physical implementation of databases. Some of the important parameter of Physical Data Model are database performance, indexing strategy, physical storage and normalization, denormalization

Once Physical Data Model is completed, it is then forwarded to technical teams for review and implementation.

In the figure below, the entity names has been changed to table names, changed attribute names to column names, assigned nullability constraints, and datatype for each column.

Tags:

Data Modeling

Tag cloud