# TAC Appt Appt

{% code title="tac\_appt\_appt" overflow="wrap" lineNumbers="true" %}

```plsql
 WITH status_calculated AS (
         SELECT date_trunc('day'::text, appt.appt_date)::date AS date,
            to_char(date_trunc('month'::text, appt.appt_date), 'YYYY Mon'::text) AS month,
            (to_char(date_trunc('week'::text, appt.appt_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, appt.appt_date) + '6 days'::interval, 'DD Mon'::text) AS week,
            appt.branch,
            appt.contact_owner,
            appt.assigned_pic,
            appt.created_by,
                CASE
                    WHEN bool_or(appt."is_tour_show?") THEN true
                    WHEN bool_or(appt."is_trial_show?") THEN true
                    WHEN bool_or(appt."is_trial_show?") IS FALSE THEN false
                    WHEN bool_or(appt."is_tour_show?") IS FALSE THEN false
                    WHEN bool_or(appt."is_trial_show?") IS NULL THEN NULL::boolean
                    WHEN bool_or(appt."is_tour_show?") IS NULL THEN NULL::boolean
                    ELSE NULL::boolean
                END AS status,
            count(appt.appt_date) AS appt
           FROM appt
          WHERE appt.hide IS NULL OR appt.hide = false
          GROUP BY (date_trunc('day'::text, appt.appt_date)::date), (to_char(date_trunc('month'::text, appt.appt_date), 'YYYY Mon'::text)), ((to_char(date_trunc('week'::text, appt.appt_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, appt.appt_date) + '6 days'::interval, 'DD Mon'::text)), appt.branch, appt.contact_owner, appt.assigned_pic, appt.created_by
        )
 SELECT date,
    month,
    week,
    branch,
    contact_owner,
    assigned_pic,
    created_by,
    status,
    sum(appt) AS appt
   FROM status_calculated
  GROUP BY date, month, week, branch, contact_owner, assigned_pic, created_by, status
  ORDER BY date;
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://work.bahrul.me/work/kyzn/database-management/table-view/tac-appt-appt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
