# Appt View

{% code title="appt\_view" overflow="wrap" lineNumbers="true" %}

```plsql
 SELECT appt_id,
    visit_category,
    appt_category,
    name,
    phone,
    uid,
    tour_date,
    "is_tour_show?",
    trial_date,
    "is_trial_show?",
    assigned_pic,
    mql_date,
    trial_class,
    visit_notes,
    "is_mql?",
    "is_mqlPlus?",
    "is_tourPlus?",
    "is_trialPlus?",
    contact_owner,
    created_by,
    assign_to_team,
    class_category,
    "mqlPlus_date",
    missed_date,
    "tourPlus_date",
    "trialPlus_date",
    family_id,
    branch,
    progress,
        CASE
            WHEN tour_date IS NULL AND trial_date IS NOT NULL THEN trial_date
            WHEN trial_date IS NULL AND tour_date IS NOT NULL THEN tour_date
            WHEN tour_date IS NOT NULL AND trial_date IS NOT NULL THEN GREATEST(tour_date, trial_date)
            ELSE NULL::timestamp without time zone
        END AS appt_date,
    (to_char(date_trunc('week'::text,
        CASE
            WHEN tour_date IS NULL AND trial_date IS NOT NULL THEN trial_date
            WHEN trial_date IS NULL AND tour_date IS NOT NULL THEN tour_date
            WHEN tour_date IS NOT NULL AND trial_date IS NOT NULL THEN GREATEST(tour_date, trial_date)
            ELSE NULL::timestamp without time zone
        END), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text,
        CASE
            WHEN tour_date IS NULL AND trial_date IS NOT NULL THEN trial_date
            WHEN trial_date IS NULL AND tour_date IS NOT NULL THEN tour_date
            WHEN tour_date IS NOT NULL AND trial_date IS NOT NULL THEN GREATEST(tour_date, trial_date)
            ELSE NULL::timestamp without time zone
        END) + '6 days'::interval, 'DD Mon'::text) AS week_appt_date,
    (to_char(date_trunc('week'::text, mql_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, mql_date) + '6 days'::interval, 'DD Mon'::text) AS week_mql,
    (to_char(date_trunc('week'::text, "mqlPlus_date"), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, "mqlPlus_date") + '6 days'::interval, 'DD Mon'::text) AS week_mqlplus,
    (to_char(date_trunc('week'::text, "tourPlus_date"), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, "tourPlus_date") + '6 days'::interval, 'DD Mon'::text) AS week_tourplus,
    (to_char(date_trunc('week'::text, "trialPlus_date"), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, "trialPlus_date") + '6 days'::interval, 'DD Mon'::text) AS week_trialplus,
    hide,
    q1_rate_class,
    q2_class_time,
    q3_class_prices,
    q4_join_member
   FROM appt
  WHERE hide IS NULL OR hide = false;
```

{% 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/appt-view.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.
