Tag sql insert

SQL DAY Function

Example Return the day of the month for a date: SELECT DAY(‘2017/08/25’) AS DayOfMonth; Definition and Usage The DAY() function returns the day of the month (from 1 to 31) for a specified date. Syntax DAY(date)

SQL DATEPART Function

Example Return a specified part of a date: SELECT DATEPART(year, ‘2017/08/25’) AS DatePartInt; Definition and Usage The DATEPART() function returns a specified part of a date. This function returns the result as an integer value. Syntax DATEPART(interval, date)

SQL DATENAME Function

Example Return a specified part of a date: SELECT DATENAME(year, ‘2017/08/25’) AS DatePartString; Definition and Usage The DATENAME() function returns a specified part of a date. This function returns the result as a string value. Syntax DATENAME(interval, date)

SQL DATEFROMPARTS Function

Example Return a date from its parts: SELECT DATEFROMPARTS(2018, 10, 31) AS DateFromParts; Definition and Usage The DATEFROMPARTS() function returns a date from the specified parts (year, month, and day values). Syntax DATEFROMPARTS(year, month, day)

SQL DATEDIFF Function

Example Return the difference between two date values, in years: SELECT DATEDIFF(year, ‘2017/08/25’, ‘2011/08/25’) AS DateDiff; Definition and Usage The DATEDIFF() function returns the difference between two dates, as an integer. Syntax DATEDIFF(interval, date1, date2)

SQL DATEADD Function

Example Add one year to a date, then return the date: SELECT DATEADD(year, 1, ‘2017/08/25’) AS DateAdd; Definition and Usage The DATEADD() function adds a time/date interval to a date and then returns the date. Syntax DATEADD(interval, number, date)

SQL CURRENT_TIMESTAMP Function

Example Return the current date and time: SELECT CURRENT_TIMESTAMP; Definition and Usage The CURRENT_TIMESTAMP function returns the current date and time, in a ‘YYYY-MM-DD hh:mm:ss.mmm’ format. Tip: Also look at the GETDATE() function.

SQL TAN Function

Example Return the tangent of a number: SELECT TAN(1.75); Definition and Usage The TAN() function returns the tangent of a number. Syntax TAN(number)

SQL SUM Function

Example Return the sum of the “Quantity” field in the “OrderDetails” table: SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails; Definition and Usage The SUM() function calculates the sum of a set of values. Note: NULL values are ignored. Syntax SUM(expression)