Loading...
Loading...
Complete T-SQL function reference for SQL Server and Azure SQL Database. Use this skill when: (1) User asks about T-SQL string, date, math, or conversion functions, (2) User needs help with window/ranking functions, (3) User works with JSON or XML in T-SQL, (4) User asks about aggregate functions or GROUP BY, (5) User needs system or metadata functions.
npx skill4agent add josiahsiegel/claude-plugin-marketplace tsql-functions| Function | Description | Version |
|---|---|---|
| NULL-safe concatenation | 2012+ |
| Concatenate with separator | 2017+ |
| Aggregate strings | 2017+ |
| Split to rows | 2016+ |
| With ordinal column | 2022+ |
| Remove leading/trailing | 2017+ |
| Character replacement | 2017+ |
| .NET format strings | 2012+ |
| Function | Description | Version |
|---|---|---|
| Add interval | All |
| Difference (int) | All |
| Difference (bigint) | 2016+ |
| Last day of month | 2012+ |
| Truncate to precision | 2022+ |
| Group into buckets | 2022+ |
| Timezone conversion | 2016+ |
| Function | Description | Version |
|---|---|---|
| Sequential unique numbers | 2005+ |
| Rank with gaps for ties | 2005+ |
| Rank without gaps | 2005+ |
| Distribute into n groups | 2005+ |
| Previous row value | 2012+ |
| Next row value | 2012+ |
| First in window | 2012+ |
| Last in window | 2012+ |
| Skip NULLs in offset funcs | 2022+ |
| Function | Description |
|---|---|
| Maximum of values |
| Minimum of values |
| Truncate date |
| Number sequence |
| Create JSON object |
| Create JSON array |
| Check path exists |
| NULL-safe comparison |
-- Concatenate with separator (NULL-safe)
SELECT CONCAT_WS(', ', FirstName, MiddleName, LastName) AS FullName
-- Split string to rows with ordinal
SELECT value, ordinal
FROM STRING_SPLIT('apple,banana,cherry', ',', 1)
-- Aggregate strings with ordering
SELECT DeptID,
STRING_AGG(EmployeeName, ', ') WITHIN GROUP (ORDER BY HireDate)
FROM Employees
GROUP BY DeptID-- Truncate to first of month
SELECT DATETRUNC(month, OrderDate) AS MonthStart
-- Group by week buckets
SELECT DATE_BUCKET(week, 1, OrderDate) AS WeekBucket,
COUNT(*) AS OrderCount
FROM Orders
GROUP BY DATE_BUCKET(week, 1, OrderDate)
-- Generate date series
SELECT CAST(value AS date) AS Date
FROM GENERATE_SERIES(
CAST('2024-01-01' AS date),
CAST('2024-12-31' AS date),
1
)-- Running total with partitioning
SELECT OrderID, CustomerID, Amount,
SUM(Amount) OVER (
PARTITION BY CustomerID
ORDER BY OrderDate
ROWS UNBOUNDED PRECEDING
) AS RunningTotal
FROM Orders
-- Get previous non-NULL value (SQL 2022+)
SELECT Date, Value,
LAST_VALUE(Value) IGNORE NULLS OVER (
ORDER BY Date
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
) AS PreviousNonNull
FROM Measurements-- Extract scalar value
SELECT JSON_VALUE(JsonColumn, '$.customer.name') AS CustomerName
-- Parse JSON array to rows
SELECT j.ProductID, j.Quantity
FROM Orders
CROSS APPLY OPENJSON(OrderDetails)
WITH (
ProductID INT '$.productId',
Quantity INT '$.qty'
) AS j
-- Build JSON object (SQL 2022+)
SELECT JSON_OBJECT('id': CustomerID, 'name': CustomerName) AS CustomerJson
FROM Customersreferences/string-functions.mdreferences/window-functions.md