Query SQL statement with date added

Source: Internet
Author: User
Keywords Network programming Database synthesis
Tags access added date function functions network network programming operation

Query SQL statement with date added
This is an SQL statement about the date added to the MSSQL access, which provides a large number of functions for the database tutorial date operation, and today our date is added using the DateAdd function for instance.
*/

Method one stored procedure

SET NOCOUNT ON
declare @kp table ([id] int,[ys] int,[syrq] datetime)
Insert @kp
Select 1,2, ' 2008-08-08 ' UNION ALL
Select 2,3, ' 2008-09-01 ' UNION ALL
Select 3, 33, ' 2008-08-11 '

Select Id,dateadd (MONTH,YS,SYRQ) as Syrq from @kp

Method two simple query statements

Select DATEADD (Month,cast (ys as int), SYRQ) as new date from KP
Method three DateAdd function date added

DATEADD (d,5, "2008-08-08")

DATEADD (d,5, "2008-08-08")

Sqlstr= "SELECT * from table where Time field =dateadd (d,5, ' 2008-08-08 ')"

Select DATEADD (D,5,cast (' 2008-08-08 ' as datetime)
Select cast (' 2008-08-08 ' as datetime)

2008-08-13 00:00:00.000
2008-08-08 00:00:00.000
Look at the date add SQL instance

Use pubs
Go
Select DateAdd (days, pubdate) as timeframe
from titles
went
/*
DateAdd function returns a date containing a   Variant (date), which adds a time interval. The syntax DateAdd (interval, number, date) has the following named parameters in the DATEADD function syntax: Partial description interval necessary.   string expression, which is the time interval to add. Number is necessary. Numeric expression, which is the number of time intervals to add.   The value can be positive (get a future date), or it can be negative (get past date). Date necessary.   Variant (date) or text that represents a date, plus a time interval. Setting the interval parameter has the following set of values: Set description yyyy year Q quarter m month y a year day number d days of the week of the WW weekly hh n minutes S
*/

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.