SQL LENGTH

Returns the number of characters in a string — including any leading, trailing, or internal whitespace, which is exactly why it's a useful diagnostic tool.

What & Why

LENGTH(text) returns a character count. It counts everything — spaces included — which makes it a genuinely useful way to spot whitespace problems that aren't visible just by looking at a value.

See How It Works

BUSINESS QUESTION

Marketing wants campaign-name lengths so unusually short or long labels can be reviewed.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
SELECT
  id AS campaign_id,
  name,
  LENGTH(name) AS name_length
FROM marketing.campaigns
ORDER BY name_length DESC, campaign_id;
RESULT — exact output from the displayed Queryflo rows
campaign_idnamename_length
3Finance Retargeting19
2Retention Webinar17
4Enterprise Search17
1Spring Launch13

The displayed lengths are calculated from the exact campaign names.

Intermediate business practice

Sign up free to try it on a real business scenario