SQL time and string is taken to the millisecond level

Source: Internet
Author: User
Tags getdate

(Select replace (CONVERT (varchar, GETDATE (), +), '-', '), ', '), ': ', ') + (select Right (CONVERT ( varchar (+), GETDATE (), 126), 3) as [UserID])

Reproduced below from: http://blog.sina.com.cn/s/blog_4605821b010005qj.html

1. Learn the functions of SQL intercept string

The most commonly used interception function is left,right,substring

1.LEFT ( character_expression , integer_expression )

Returns the specified number of characters starting from the left of the string

Example: Left ("field name", intercepting several strings)

The following example uses the left function to return the leftmost 2 character of a string abcdefg.

SELECT LEFT(‘abcdefg‘,2)GO

Here is the result set:

-- ab

2。RIGHT ( character_expression , integer_expression )

返回字符串中从右边开始指定个数的 integer_expression 字符

举例说明:RIGHT(“字段名”,截取几位字符串)

The following example uses the right function to return the rightmost 2 character of a string abcdefg.

SELECT right(‘abcdefg‘,2)GO

Here is the result set:

-- fg

3.SUBSTRING ( expression , start , length )

返回字符、binary、text 或 image 表达式的一部分

举例说明:SUBSTRING(“字段名”,第几位开始,截取几位字符串)

Displays the second, third, and fourth characters in a string constant abcdef.

SELECT x = SUBSTRING(‘abcdef‘, 2, 3)

Here is the result set:

x----------bcd

SQL time and string is taken to the millisecond level

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.