SQL सर्वर कन्वर्ट () फ़ंक्शन
उदाहरण
एक अभिव्यक्ति को int में बदलें:
SELECT CONVERT(int, 25.65);
परिभाषा और उपयोग
CONVERT () फ़ंक्शन एक मान (किसी भी प्रकार का) को एक निर्दिष्ट डेटाटाइप में परिवर्तित करता है।
युक्ति: CAST() फ़ंक्शन को भी देखें ।
वाक्य - विन्यास
CONVERT(data_type(length), expression, style)
पैरामीटर मान
Value | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data_type | Required. The datatype to convert expression to. Can be one of the following: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(length) | Optional. The length of the resulting data type (for char, varchar, nchar, nvarchar, binary and varbinary) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expression | Required. The value to convert to another data type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
style | Optional. The format used to convert between data types, such as a date
or string format. Can be one of the following values:
Converting datetime to character:
|
टेक्निकल डिटेल
काम में: | SQL सर्वर (2008 से शुरू), Azure SQL डेटाबेस, Azure SQL डेटा वेयरहाउस, समानांतर डेटा वेयरहाउस |
---|
और ज्यादा उदाहरण
उदाहरण
एक अभिव्यक्ति को एक डेटा प्रकार से दूसरे में बदलें (वर्कर):
SELECT CONVERT(varchar, 25.65);
उदाहरण
एक अभिव्यक्ति को एक डेटा प्रकार से दूसरे में बदलें (डेटाटाइम):
SELECT CONVERT(datetime, '2017-08-25');
उदाहरण
एक अभिव्यक्ति को एक डेटा प्रकार से दूसरे में बदलें (वर्कर):
SELECT CONVERT(varchar,
'2017-08-25', 101);