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:-
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.....