Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
CASE (simple)
Mit „simple CASE“ wird ein Ergebnis basierend auf dem Wert eines einzelnen Eingabeausdrucks zurückgegeben. Wenn keiner der Vergleichswerte übereinstimmt, wird ein Standardergebnis zurückgegeben.
CASE Payment Type
WHEN "CC" THEN "Credit Card"
WHEN "DC" THEN "Debit Card"
WHEN "GC" THEN "Gift Card"
WHEN "CA" THEN "Cash"
ELSE "Other"
END
Syntax
CASE input_expression
WHEN expression_to_match THEN result
[WHEN expression_to_match THEN result]
[...]
[ELSE else_result]
END
Parameter
input_expression: alle gültigen Felder oder Ausdrücke.
[expression_to_match: alle gültigen Felder oder Ausdrücke. Die WHEN-Klausel vergleicht input_expression mit input_expression und gibt „true“ zurück, wenn die beiden übereinstimmen, und „false“, wenn nicht.]{#when-conditions}
result : alle gültigen Felder oder Ausdrücke. Jede WHEN-Anweisung muss eine übereinstimmende THEN-Anweisung haben, die die Ergebnisse angibt, die zurückgegeben werden sollen, wenn diese Bedingung erfüllt ist. Wenn es mehrere WHEN-Anweisungen gibt, gibt die CASE-Anweisung das Ergebnis für die erste wahre Anweisung zurück.
else_result (optional): alle gültigen Felder oder Ausdrücke. Die ELSE-Klausel else_result gibt ein Standardergebnis für die CASE-Anweisung an. Sie wird zurückgegeben, falls keine der WHEN-Anweisungen erfüllt ist. Wenn eine CASE-Anweisung keine ELSE-Klausel enthält und keine der WHEN-Klauseln zutrifft, gibt die CASE-Anweisung NULL zurück.
So funktioniert CASE
Eine einfache CASE-Anweisung besteht aus den folgenden Elementen:
Das Schlüsselwort CASE, gefolgt von einem Eingabeausdruck.
WHEN : Wert, mit dem input_expression verglichen wird : Wenn der Wert mit input_expression übereinstimmt, wird für diese Anweisung „true“ zurückgegeben. Eine CASE-Anweisung kann mehrere WHEN-Anweisungen enthalten.
THEN : das Ergebnis, das zurückgegeben wird, wenn die Bedingung der WHEN-Anweisung erfüllt ist. Für jede WHEN-Klausel in Ihrer CASE-Anweisung muss eine THEN-Klausel vorhanden sein.
ELSE : Optional. Wenn keine Bedingung der WHEN-Anweisung erfüllt ist, gibt CASE den Wert der ELSE-Anweisung zurück oder NULL, wenn keine ELSE-Anweisung angegeben ist.
Das Keyword END.
CASE wertet jede aufeinanderfolgende WHEN-Anweisung aus und gibt das erste Ergebnis zurück, bei dem die Bedingung erfüllt ist. Alle verbleibenden WHEN-Klauseln und das ELSE-Ergebnis werden nicht ausgewertet. Wenn alle WHEN-Bedingungen falsch sind oder NULL, gibt CASE das Ergebnis ELSE zurück. Wenn es keine ELSE-Anweisung gibt, wird der Wert NULL zurückgegeben.
Beispiel
Individuelle Links für Ihre Premiumkunden angeben:
CASE Premium Status
WHEN "Platinum" THEN CONCAT(Site URL, "platinum_welcome.html")
WHEN "Gold" THEN CONCAT(Site URL, "gold_welcome.html")
WHEN "Silver" THEN CONCAT(Site URL, "silver_welcome.html")
ELSE CONCAT(Site URL, "welcome.html")
END
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-25 (UTC)."],[],[],null,["CASE (simple)\n=============\n\nSimple `CASE` returns a result based on the value of a single input expression, or a default result if none of the comparison values match.\n| **Note:** There are two forms of the `CASE` statement: *searched* `CASE` and *simple* `CASE`. Searched `CASE` statements allow you to use more sophisticated logic, while simple `CASE` statements are simpler to construct.\n\nSee also: [IF](/looker/docs/studio/if).\n\nSample usage\n------------\n\nReplace payment codes with intuitive names: \n\n```\n CASE Payment Type\n WHEN \"CC\" THEN \"Credit Card\"\n WHEN \"DC\" THEN \"Debit Card\"\n WHEN \"GC\" THEN \"Gift Card\"\n WHEN \"CA\" THEN \"Cash\"\n ELSE \"Other\"\n END\n```\n\nSyntax\n------\n\n```\n CASE input_expression\n WHEN expression_to_match THEN result\n [WHEN expression_to_match THEN result]\n [...]\n [ELSE else_result]\n END\n```\n\n### Parameters\n\n- \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e - Any valid field or expression.\n- \\[\u003cvar translate=\"no\"\u003eexpression_to_match\u003c/var\u003e - Any valid field or expression. The `WHEN` clause compares \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e to \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e and returns true if the two are equal, or false if they aren't.\\]{#when-conditions}\n- \u003cvar translate=\"no\"\u003eresult \u003c/var\u003e - Any valid field or expression. Each `WHEN` clause must have a matching `THEN` clause, which specifies the results to return if that condition is true. If there are multiple `WHEN` clauses, the `CASE` statement returns the result for the first true clause.\n- \u003cvar translate=\"no\"\u003eelse_result\u003c/var\u003e (optional) - Any valid field or expression. The `ELSE` *else_result* clause specifies a default result for the `CASE` statement. This clause is returned if none of the `WHEN` clauses are true. If a `CASE` statement has no `ELSE` clause, and none of the `WHEN` clauses are true, the `CASE` statement returns `NULL`.\n\n| **Note:** All of the `THEN` clauses in a `CASE` statement must return the same type of result. For example, if the first `THEN` clause returns the **Text** data type, additional `THEN` clauses must also return the **Text** data type.\n\nHow simple `CASE` works\n-----------------------\n\nA simple `CASE` statement consists of the following elements:\n\n- The `CASE` keyword, followed by an input expression.\n- `WHEN` : the value against which to compare the \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e : if the value equals the \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e, then this clause is true. You can have multiple `WHEN` clauses in a single `CASE` statement.\n- `THEN` : the result to return if the `WHEN` clause's condition is true. You must have one `THEN` clause for each `WHEN` clause in your `CASE` statement.\n- `ELSE` : Optional. If none of the `WHEN` clause conditions are true, `CASE` returns the value in the `ELSE` clause, or `NULL` if no `ELSE` clause is specified.\n- The `END` keyword.\n\n`CASE` evaluates each successive `WHEN` clause and returns the first result where the condition is true. Any remaining `WHEN` clauses and the `ELSE` result are not evaluated. If all `WHEN` conditions are false or `NULL`, `CASE` returns the `ELSE` result, or if no `ELSE` clause is present, returns `NULL`.\n\nExample\n-------\n\nProvide customized links for your premium customers: \n\n```\n CASE Premium Status\n WHEN \"Platinum\" THEN CONCAT(Site URL, \"platinum_welcome.html\")\n WHEN \"Gold\" THEN CONCAT(Site URL, \"gold_welcome.html\")\n WHEN \"Silver\" THEN CONCAT(Site URL, \"silver_welcome.html\")\n ELSE CONCAT(Site URL, \"welcome.html\")\n END\n```\n\nRelated resources\n-----------------\n\n- [Calculated fields](/looker/docs/studio/about-calculated-fields)\n- [Looker Studio function list](/looker/docs/studio/function-list)"]]