> For the complete documentation index, see [llms.txt](https://dailyjournal.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dailyjournal.gitbook.io/notes/databases/relational-databases/microsoft-sql-server/basics.md).

# Basics

## Batch Separators

* **Batch Separators combine one or more SQL statements that are sent to the engine as one set of statements.**&#x20;
* **Any variable declared in the current batch will not be visible in the next batch.**

```
GO
```

## Variables

```sql
DECLARE @variable_name data_type = value
```

## Functions

### String Functions

SUBSTRING()

REPLACE()

### Mathematical Functions

ROUND()

CIEL()

### Date Functions

<table><thead><tr><th width="235">Function</th><th></th></tr></thead><tbody><tr><td>ISDATE()</td><td>validates date and time</td></tr><tr><td>GETDATE()</td><td>return current date and time</td></tr><tr><td>DATEFROMPARTS()</td><td>requires year, month and day</td></tr><tr><td>DATETIMEFROMPARTS()</td><td>requires year, month, day along with hour, minute, second, millisecond</td></tr><tr><td>DATEADD()</td><td>can add/subract to/from date and time</td></tr><tr><td>EOMONTH()</td><td>returns the last date of the specified month<br><code>EOMONTH(GETDATE())</code></td></tr><tr><td>DATEDIFF()</td><td>returns the difference between the specified dates</td></tr></tbody></table>

| DATENAME()                                       | DATEPART()                                                    |
| ------------------------------------------------ | ------------------------------------------------------------- |
| `SELECT DATENAME(MONTH, GETDATE())`              | `SELECT DATEPART(MONTH, GETDATE())`                           |
| <p>Output</p><p>February (Name of the Month)</p> | <p>Output</p><p>2 (Numerical representation of the month)</p> |

### Window Functions

```sql
window_function( [ ALL ] expression )
OVER ( [ PARTITION BY partition_list ] [ ORDER BY order_list ] );
```

* Value Window Functions\
  `FIRST_VALUE(), LAG(), LAST_VALUE(), LEAD()`

## `MERGE`

{% embed url="<https://www.scaler.com/topics/merge-in-sql/>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://dailyjournal.gitbook.io/notes/databases/relational-databases/microsoft-sql-server/basics.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
