Functies voor het bewerken van data in SQL Server
Ana Voicu
Data Engineer
Definitie
Syntaxis
LEN(character_expression)
SELECT LEN('Do you know the length of this sentence?') AS length
|lengte|
|------|
|40 |
SELECT DISTINCT TOP 5
bean_origin,
LEN(bean_origin) AS length
FROM ratings;
|bean_origin |lengte|
|------------------------|------|
|Toscano Black |13 |
|Trinite |7 |
|Ocumare- Puerto Cabello |23 |
|Maracaibo- El Rosario |21 |
|Madagascar |10 |
Definitie
Syntaxis
CHARINDEX (expression_to_find, expression_to_search [, start_location])
SELECT
CHARINDEX('chocolate', 'White chocolate is not real chocolate'),
CHARINDEX('chocolate', 'White chocolate is not real chocolate',10),
CHARINDEX('chocolates', 'White chocolate is not real chocolate');
|positie begin|positie in string|positie van niet-bestaande exp|
|-------------|------------------|-------------------------------|
|7 |29 |0 |
Definitie
Lijkt op CHARINDEX()
Geeft de beginpositie van een patroon in een expressie terug
Syntaxis
PATINDEX ('%pattern%', expression, [location ])
| Wildcard | Uitleg |
|---|---|
| % | Komt overeen met elke tekenreeks van elke lengte (ook lengte nul) |
| _ | Komt overeen met één teken |
| [ ] | Komt overeen met elk teken in de [ ]-haken (bijv. [abc] komt overeen met a, b of c) |
SELECT
PATINDEX('%chocolate%', 'White chocolate is not real chocolate') AS position1,
PATINDEX('%ch_c%', 'White chocolate is not real chocolate') AS position2;
|positie1|positie2|
|--------|--------|
|7 |7 |
Functies voor het bewerken van data in SQL Server