# 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/" %}
