Jump to content

Creating query using functions and text fields


jwoker

Recommended Posts

I want to list records where there is a value (not empty) in one of three fields and I thought I would use the length function to test if the field had a value or not. I can create a column in my result using length() but can't use it in my where clause. Here's how I initially tried to solve the problem but it failed - hopefully someone can see what I was trying to accomplish and help me get there - Thanks!

SELECTprojects.UserId,projects.Name,projects.Categories,LENGTH(projects.GeneratorUse) as LgenFROMprojectsWHEREprojects.Lgen >  0[Err] 1054 - Unknown column 'projects.Lgen' in 'where clause'
Link to comment
Share on other sites

Figured it out - Having was the solution.

 

SELECT
projects.UserId,
projects.Name,
projects.Categories,
LENGTH(projects.GeneratorUse) AS Lgen,
LENGTH(projects.FuelTypes) AS Lfue,
LENGTH(projects.FuelTypeOthers) AS Lfto,
LENGTH(projects.SpecialNeed) AS Lsn,
LENGTH(projects.FirePlan) AS Lfp
FROM
projects
HAVING
Lgen > 0 or
Lfue > 0 or
Lfto > 0 or
Lsn > 0 or
Lfp > 0
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...