SQL Server string processing functions Daquan

Source: Internet
Author: User

--╔══════════╗

--=====================================║cast function conversion ║

--╚══════════╝


The CAST () function syntax is as follows:

--CAST (<expression> as <data_ type>[length])

/*

"0", convert also provides a rich style for date conversion, cast only for normal date conversion


"1", Data_type is the data type defined for the SQL Server system, and the user-defined data type cannot be used here.


2, length specifies the length of the data, and the default value is 30.

*/


--★ Instance ★


Select CONVERT (nvarchar,123)--Return 123


Select N ' Age: ' +convert (nvarchar,23)

--Return Age: 23 (Note: If you want to display Chinese correctly in the results, you need to precede the given string with N, plus n to make the database recognize Unicode characters)


Select convert (nvarchar, getdate ())

--Return to 10:21pm


Select convert (nvarchar, GETDATE (), 101)

--Back to 04/28/2009


Select convert (nvarchar, getdate (), 120)

--Return 2009-04-28 12:22:21


Select convert (nvarchar), GETDATE (), 120)

--Back to 2009-04-28


--╔══════════╗

--=================================║convert function conversion ║

--╚══════════╝


The-CONVERT () function syntax is as follows:

--CONVERT (<data_ type>[length], <expression> [, Style])

/*

"0", convert also provides a rich style for date conversion, cast only for normal date conversion


"1", Data_type is the data type defined for the SQL Server system, and the user-defined data type cannot be used here.


2, length specifies the length of the data, and the default value is 30.

*/


--★ Instance ★


Select CAST (123 as nvarchar)--return 123

Select N ' Age: ' +cast (nvarchar)--return Age: 23


--╔══════════╗

--====================================║ parameter Description ║

--╚══════════╝

/*


3. Convert char or varchar type to an integer type such as int or samllint, and the result must be a number with a plus sign (+) or minus (-).


4, the text type to char or varchar type conversions to a maximum of 8,000 characters, that is, the char or varchar data type is the maximum length.


5. The image type stores data converted to binary or varbinary type with a maximum of 8,000 characters.


6, convert the integer value to Money or smallmoney type, according to the definition of the country's currency units to deal with, such as RMB, USD, GBP and so on.


7. A bit type conversion converts a non-0 value to 1 and is still stored as a bit type.


8. Attempts to convert to a different length of data type will truncate the conversion value and display "+" after the value is converted to identify that this truncation has occurred.

*/


SQL Server string processing functions Daquan

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.