# Capstone 2.1 2.2 and 2.3

**URL:** <https://forum.kx.com/t/capstone-2-1-2-2-and-2-3/15530>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [July 6, 2026, 9:38am UTC](https://forum.kx.com/t/capstone-2-1-2-2-and-2-3/15530 "2026-07-06T09:38:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yinzhihong12](https://avatars.discourse-cdn.com/v4/letter/y/439d5e/32.png) [@yinzhihong12](https://forum.kx.com/u/yinzhihong12)\
**Post date:** [July 6, 2026, 9:38am UTC](https://forum.kx.com/t/capstone-2-1-2-2-and-2-3/15530/1 "2026-07-06T09:38:23Z")

</div>

I have the finished 2.1 , 2.2 and 2.3 as following:

**2.1 In the `optRef` table, the `expiry` column is in a string format. Convert this into the kdb date format.**

_Help: See [Casting](https://academy.kx.com/courses/kdb-developer-level-2/lessons/casting/topic/casting-textual-data/)_

```q
meta optRef
`optRef[`expiry]: "D"$optRef[`expiry]
//optRef

```

2.2 Create a function `extractBrokerId`

extractBrokerId:{[exMsg] parts: "-" vs exMsg;  
exch: parts 0;  
$[exch like "CME\*"; brokerId:parts 2; brokerId:parts 1];  
:"J"$brokerId  
}  
//show t1: extractBrokerId["CME-TSLA20200920C1700-709"]  
//show t2: extractBrokerId["ISE-708-TSLA20200920C1700"]

2.3. Using the `extractBrokerId` function (or otherwise), update the `messages` table

//select broker\_id: extractBrokerId each string each exch\_message from messages  
messages: select trade\_id, exch\_message, broker\_id: extractBrokerId each string each exch\_message from messages  
//meta messages

but the testSection[`exercise2] shows:

## quizItem success description error

exercise2.1 Fail "optRef Has Correct Format" ""  
exercise2.2 Fail "instRef Has Correct Format" ""  
exercise2.3 Fail "messages Has Correct Format" ""

---

<div class="post-metadata">

**Author:** ![lkerr2](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/lkerr2/32/57_2.png) [@lkerr2](https://forum.kx.com/u/lkerr2)\
**Post date:** [July 6, 2026, 10:08am UTC](https://forum.kx.com/t/capstone-2-1-2-2-and-2-3/15530/2 "2026-07-06T10:08:05Z")

</div>

> [@yinzhihong12](#):
>
> ``optRef[`expiry]: "D"$optRef[`expiry]`

Hi @yinzhihong12 ,

When I run your code above for 2.1 optRef I get an NYI error. I would recommend using an update statement for casting the type of the expiry column.

Your code for 2.2 looks fine, but for 2.3 you can use an update statement instead of selecting, and you don't need the each string in your statement.

Hope this helps! Let me know if you're still getting errors.

Laura
