1. CAST:-
-- CAST
-- CAST Function is used to convert the data from one data type to another data type
-- Example -1
SELECT CAST('46543.8798' AS FLOAT) AS [Float_Val],
CAST('46543.8798' AS DECIMAL) AS [Decimal_Val],
CAST('46543.8798' 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=240
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, '46543.8798') AS [Float_Val],
CONVERT(DECIMAL, '46543.8798') AS [Decimal_Val],
CONVERT(DECIMAL(7,2), '46543.8798') AS [Decimal_Value_with_length],
CONVERT(DATETIME,'01/13/2012') AS [Date_Val]
-- CAST
-- CAST Function is used to convert the data from one data type to another data type
-- Example -1
SELECT CAST('46543.8798' AS FLOAT) AS [Float_Val],
CAST('46543.8798' AS DECIMAL) AS [Decimal_Val],
CAST('46543.8798' 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=240
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, '46543.8798') AS [Float_Val],
CONVERT(DECIMAL, '46543.8798') AS [Decimal_Val],
CONVERT(DECIMAL(7,2), '46543.8798') AS [Decimal_Value_with_length],
CONVERT(DATETIME,'01/13/2012') AS [Date_Val]
No comments:
Post a Comment