Thursday 29 December 2016

SQL SERVER -- Conversion Functions-- Part-21

SQL SERVER -- Conversion Functions-- Part-21

                   Conversion Functions are used to convert the data from one data type to another.

There are 2 types of CONVERT Functions available.

1. CAST:-  

-- CAST
-- CAST Function is used to convert the data from one data type to another data type
-- Example -1
SELECT CAST('56543.7897' AS FLOAT) AS [Float_Val],
       CAST('56543.7897' AS DECIMAL) AS [Decimal_Val],
       CAST('56543.7897' AS DECIMAL(7,2)) AS [Decimal_Value_with_length],
       CAST('01/13/2012' AS DATETIME) as [Date_Val]

 -- Example -2
DECLARE @A INT
DECLARE @B VARCHAR(100)
SET @A=100
SET @B='The Given Number is: '
--SELECT @B+@A AS TOTAL

SELECT @B+CAST(@A AS VARCHAR) AS TOTAL



2. CONVERT:-  

-- CONVERT
-- CONVERT Function is used to convert the data from one data type to another data type
-- Example -1
SELECT CONVERT(FLOAT, '56543.7897') AS [Float_Val],
       CONVERT(DECIMAL, '56543.7897') AS [Decimal_Val],
       CONVERT(DECIMAL(7,2), '56543.7897') AS [Decimal_Value_with_length],
       CONVERT(DATETIME,'01/13/2012') AS [Date_Val]


 -- Example -2
DECLARE @A INT
DECLARE @B VARCHAR(100)
SET @A=100
SET @B='The Given Number is: '
--SELECT @B+@A AS TOTAL

SELECT @B+CONVERT(VARCHAR,@A) AS TOTAL






Thanks for Looking into this.....







6 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Thanks for giving this valuable information . So kindly provide aws online training in hyderabad
    linux online training in hyderabad

    ReplyDelete
  3. Thanks for giving this valuable information . So kindly provide aws online training in hyderabad
    linux online training in hyderabad

    ReplyDelete
  4. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    SEO Company in India

    ReplyDelete
  5. Very Nice Blog its Really Helpfull for me

    ReplyDelete
  6. Thank You Guys for your Comments.

    ReplyDelete