DtSQL



DtSQL is a universal database query and editor tool for developers and database administrators to Query, Edit, Browse, and Manage Databases. It can access most databases and can be used on all major operating systems.

In SQL Server 2005 I have a table cmproduction that lists all the code that's been put into production. The table has a ticketnumber, programtype, and programname and pushnumber along with some. DtSQL is a database tools for developers and database administrators to query, edit, browse, and manage database objects. It can access most databases and can be used on all major operating systems.

Supported Databases

DtSQL is a database tools for developers and database administrators to query, edit, browse, and manage database objects. It can access most databases and can be used on all major operating systems.

  • Cache
  • DB2
  • Derby
  • Firebird
  • FrontBase
  • H2
  • HSQLDB
  • Informix
  • Ingres
  • JDatastore
  • MaxDB
  • Mckoi
  • Mimer
  • MySQL
  • Oracle
  • PointBase
  • PostgresSQL
  • Solid
  • SQLite
  • SQL Server
  • SQL Anywhere
  • Sybase (ASE)
Features
  • Database Browser: browse schemas, tables, columns, primary and foreign keys, constraints, views, indexes, triggers, stored procedures, functions, sequences, and so on.
  • Database Tools: create, alter, view and drop tables, views, indexes, constraints, stored procedures, functions, triggers, sequences, and so on
  • Data Management: edit table data including binary/BLOB and CLOB data types. Filter, sort and search query result. Insert, duplicate, update, and delete table data. Find and replace data, preview generated SQL. Redo or undo last table data change before update is committed.
  • SQL Tools edit, format and execute SQL scripts.
  • SQL Builder: help tools to build select, insert, update, delete SQL scripts.
  • Import Data: import data from various formats such as CSV files, Excel files, and fixed-width files. Parse import data according to integer, date, time, timestamp, and boolean pattern.
  • Export Data: export data (single table/multiple tables/query result) in various formats such as CSV files, Excel files, XML, HTML, SQL insert statements and fixed width files. Format export data according to applied integer, date, time, timestamp, and boolean pattern.
-->

Applies to: SQL Server (all supported versions) Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Parallel Data Warehouse

This function adds a specified number value (as a signed integer) to a specified datepart of an input date value, and then returns that modified value.

See Date and Time Data Types and Functions (Transact-SQL) for an overview of all Transact-SQL date and time data types and functions.

Syntax

Note

To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

Arguments

datepart
The part of date to which DATEADD adds an integernumber. This table lists all valid datepart arguments.

Note

DATEADD does not accept user-defined variable equivalents for the datepart arguments.

datepartAbbreviations
yearyy, yyyy
quarterqq, q
monthmm, m
dayofyeardy, y
daydd, d
weekwk, ww
weekdaydw, w
hourhh
minutemi, n
secondss, s
millisecondms
microsecondmcs
nanosecondns

number
An expression that can resolve to an int that DATEADD adds to a datepart of date. DATEADD accepts user-defined variable values for number. DATEADD will truncate a specified number value that has a decimal fraction. It will not round the number value in this situation.

date
An expression that can resolve to one of the following values:

Dtsl
  • date
  • datetime
  • datetimeoffset
  • datetime2
  • smalldatetime
  • time

For date, DATEADD will accept a column expression, expression, string literal, or user-defined variable. A string literal value must resolve to a datetime. Use four-digit years to avoid ambiguity issues. See Configure the two digit year cutoff Server Configuration Option for information about two-digit years.

Return types

The return value data type for this method is dynamic. The return type depends on the argument supplied for date. If the value for date is a string literal date, DATEADD returns a datetime value. If another valid input data type is supplied for date, DATEADD returns the same data type. DATEADD raises an error if the string literal seconds scale exceeds three decimal place positions (.nnn) or if the string literal contains the time zone offset part.

Return Value

datepart Argument

dayofyear, day, and weekday return the same value.

Each datepart and its abbreviations return the same value.

If the following are true:

  • datepart is month
  • the date month has more days than the return month
  • the date day does not exist in the return month

Then, DATEADD returns the last day of the return month. For example, September has 30 (thirty) days; therefore, these statements return 2006-09-30 00:00:00.000:

Dtslb

number Argument

The number argument cannot exceed the range of int. In the following statements, the argument for number exceeds the range of int by 1. These statements both return the following error message: 'Msg 8115, Level 16, State 2, Line 1. Arithmetic overflow error converting expression to data type int.'

date Argument

DATEADD will not accept a date argument incremented to a value outside the range of its data type. In the following statements, the number value added to the date value exceeds the range of the date data type. DATEADD returns the following error message: 'Msg 517, Level 16, State 1, Line 1 Adding a value to a 'datetime' column caused overflow.'

Return Values for a smalldatetime date and a second or Fractional Seconds datepart

The seconds part of a smalldatetime value is always 00. For a smalldatetimedate value, the following apply:

  • For a datepart of second, and a number value between -30 and +29, DATEADD makes no changes.
  • For a datepart of second, and a number value less than -30, or more than +29, DATEADD performs its addition beginning at one minute.
  • For a datepart of millisecond and a number value between -30001 and +29998, DATEADD makes no changes.
  • For a datepart of millisecond and a number value less than -30001, or more than +29998, DATEADD performs its addition beginning at one minute.

Remarks

Use DATEADD in the following clauses:

  • GROUP BY
  • HAVING
  • ORDER BY
  • SELECT <list>
  • WHERE
DtSQL

Fractional seconds precision

DATEADD does not allow addition for a datepart of microsecond or nanosecond for date data types smalldatetime, date, and datetime.

Milliseconds have a scale of 3 (.123), microseconds have a scale of 6 (.123456), and nanoseconds have a scale of 9 (.123456789). The time, datetime2, and datetimeoffset data types have a maximum scale of 7 (.1234567). For a datepart of nanosecond, number must be 100 before the fractional seconds of date increase. A number between 1 and 49 will round down to 0, and a number from 50 to 99 rounds up to 100.

These statements add a datepart of millisecond, microsecond, or nanosecond.

Here is the result set.

Time zone offset

DATEADD does not allow addition for time zone offset.

Examples

A. Incrementing datepart by an interval of 1

Each of these statements increments datepart by an interval of 1:

Here is the result set.

B. Incrementing more than one level of datepart in one statement

Each of these statements increments datepart by a number large enough to additionally increment the next higher datepart of date:

C. Using expressions as arguments for the number and date parameters

These examples use different types of expressions as arguments for the number and date parameters. The examples use the AdventureWorks database.

Specifying a column as date

This example adds 2 (two) days to each value in the OrderDate column, to derive a new column named PromisedShipDate:

A partial result set:

Dtsl

Specifying user-defined variables as number and date

This example specifies user-defined variables as arguments for number and date:

Here is the result set.

Specifying scalar system function as date

This example specifies SYSDATETIME for date. The exact value returned depends on theday and time of statement execution:

Here is the result set.

Specifying scalar subqueries and scalar functions as number and date

Dtsql Download

This example uses scalar subqueries, MAX(ModifiedDate), as arguments for number and date. (SELECT TOP 1 BusinessEntityID FROM Person.Person) serves as an artificial argument for the number parameter, to show how to select a number argument from a value list.

Specifying numeric expressions and scalar system functions as number and date

This example uses a numeric expression (-(10/2)), unary operators (-), an arithmetic operator (/), and scalar system functions (SYSDATETIME) as arguments for number and date.

Specifying ranking functions as number

This example uses a ranking function as an argument for number.

Specifying an aggregate window function as number

This example uses an aggregate window function as an argument for number.

Dtsl Stock

See also