# function SUBSTRING

**URL:** <https://forum.kx.com/t/function-substring/8066>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [December 19, 2012, 4:22pm UTC](https://forum.kx.com/t/function-substring/8066 "2012-12-19T16:22:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![occhiogrosso\_gr](https://avatars.discourse-cdn.com/v4/letter/o/f14d63/32.png) [@occhiogrosso\_gr](https://forum.kx.com/u/occhiogrosso_gr)\
**Post date:** [December 19, 2012, 4:22pm UTC](https://forum.kx.com/t/function-substring/8066/1 "2012-12-19T16:22:00Z")

</div>

hi,

exist a function equivalent to SQL function substring?

---

<div class="post-metadata">

**Author:** ![P\_Bukowinski1](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@P\_Bukowinski1](https://forum.kx.com/u/P_Bukowinski1)\
**Post date:** [December 19, 2012, 4:42pm UTC](https://forum.kx.com/t/function-substring/8066/2 "2012-12-19T16:42:00Z")

</div>

good alternative would be:

1 3 sublist “test string”  
“est”

check also  
ss  
ssr  
cut

---

<div class="post-metadata">

**Author:** ![TerryLynch1](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@TerryLynch1](https://forum.kx.com/u/TerryLynch1)\
**Post date:** [December 19, 2012, 5:00pm UTC](https://forum.kx.com/t/function-substring/8066/3 "2012-12-19T17:00:00Z")

</div>

http://code.kx.com/wiki/Reference/sublist

You generally have to build these things yourself.

q)tab:( FirstName:(“foooo”;“john”);LastName:(“bar”;“Doe”))

q)

q)tab

FirstName LastName

* * *

“foooo” &nbsp; “bar”

“john” &nbsp; &nbsp;“Doe”

q)substr:{(y-1;z) sublist/:x}

q)

q)select LastName,new:substr[FirstName;2;6] from tab

LastName new

* * *

“bar” &nbsp; &nbsp;“oooo”

“Doe” &nbsp; &nbsp;“ohn”

q)

q)select LastName,new:substr[FirstName;1;2] from tab

LastName new

* * *

“bar” &nbsp; &nbsp;“fo”

“Doe” &nbsp; &nbsp;“jo”

“Cut” could also acheive this

[http://code.kx.com/wiki/Reference/cut](http://code.kx.com/wiki/Reference/cut)
