SQL Server Database date format function

Source: Internet
Author: User
Tags getdate rtrim backup

A very powerful date format function in SQL Server

Select CONVERT (varchar), GETDATE (), 0): 2006 10:57am

Select CONVERT (varchar), GETDATE (), 1): 05/16/06

Select CONVERT (varchar), GETDATE (), 2): 06.05.16

Select CONVERT (varchar), GETDATE (), 3): 16/05/06

Select CONVERT (varchar), GETDATE (), 4): 16.05.06

Select CONVERT (varchar), GETDATE (), 5): 16-05-06

Select CONVERT (varchar), GETDATE (), 6): 16 05 06

Select CONVERT (varchar), GETDATE (), 7:05 16, 06

Select CONVERT (varchar), GETDATE (): 10:57:46

Select CONVERT (varchar), GETDATE (), 9): 2006 10:57:46:827am

Select CONVERT (varchar), GETDATE (), 10): 05-16-06

Select CONVERT (varchar), GETDATE (), 11): 06/05/16

Select CONVERT (varchar), GETDATE (), 12): 060516

Select CONVERT (varchar), GETDATE (), 13:16 05 2006 10:57:46:937

Select CONVERT (varchar), GETDATE (), 14): 10:57:46:967

Select CONVERT (varchar), GETDATE (), 20): 2006-05-16 10:57:47

Select CONVERT (varchar), GETDATE (), 21): 2006-05-16 10:57:47.157

Select CONVERT (varchar (MB), GETDATE (): 05/16/06 10:57:47 AM

Select CONVERT (varchar), GETDATE (), 23): 2006-05-16

Select CONVERT (varchar), GETDATE (), 24): 10:57:47

Select CONVERT (varchar), GETDATE (), 25): 2006-05-16 10:57:47.250

Select CONVERT (varchar), GETDATE (): 2006 10:57am

Select CONVERT (varchar), GETDATE (), 101): 05/16/2006

Select CONVERT (varchar), GETDATE (), 102): 2006.05.16

Select CONVERT (varchar), GETDATE (), 103): 16/05/2006

Select CONVERT (varchar), GETDATE (), 104): 16.05.2006

Select CONVERT (varchar), GETDATE (), 105): 16-05-2006

Select CONVERT (varchar), GETDATE (), 106): 16 05 2006

Select CONVERT (varchar), GETDATE (), 107:05 16, 2006

Select CONVERT (varchar), GETDATE (), 108): 10:57:49

Select CONVERT (varchar), GETDATE (), 109): 2006 10:57:49:437am

Select CONVERT (varchar), GETDATE (), 110): 05-16-2006

Select CONVERT (varchar), GETDATE (), 111): 2006/05/16

Select CONVERT (varchar), GETDATE (), 112): 20060516

Select CONVERT (varchar), GETDATE (), 113:16 05 2006 10:57:49:513

Select CONVERT (varchar), GETDATE (), 114): 10:57:49:547

Select CONVERT (varchar), GETDATE (), 120): 2006-05-16 10:57:49

Select CONVERT (varchar), GETDATE (), 121): 2006-05-16 10:57:49.700

Select CONVERT (varchar), GETDATE (), 126): 2006-05-16t10:57:49.827

Select CONVERT (varchar), GETDATE (), 130):???? ?????? 1427 10:57:49:907am

Select CONVERT (varchar), GETDATE (), 131): 18/04/1427 10:57:49:920am

Common:

Select CONVERT (varchar), GETDATE (): 10:57:46

Select CONVERT (varchar), GETDATE (), 24): 10:57:47

Select CONVERT (varchar), GETDATE (), 108): 10:57:49

Select CONVERT (varchar), GETDATE (), 12): 060516

Select CONVERT (varchar), GETDATE (), 23): 2006-05-16

Common knowledge points in stored procedures:

Cycle

DECLARE @i int

Set @i=1

While @i<30

Begin

INSERT INTO Test (userid) VALUES (@i)

Set @i=@i+1

End

Ways to replace table names with variables

declare @fld nvarchar (255)

declare @sql nvarchar (255)

Select @fld = ' UserName '

Select @sql = ' SELECT ' + @fld + ' from TBL '

EXEC sp_executesql @sql

Backup Shrink Database

Backup LOG Register with NO_LOG

Backup LOG Register with TRUNCATE_ONLY

DBCC shrinkdatabase (Register)

SELECT [id], [gnname], RTrim ([url]) as URL, [GNSM], [GNQX] from [Bg_gnmx]

RTrim ()//Remove the space on the right

LTrim ()//Remove the left space

Note: After using the function, you must use the alias

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.