error on count query

i got a location(text) inside the variable xlocation
now, i want to count how many records have this location inside from or loc and where end is empty...

i got an error here: can you correct me please
mySQL8="SELECT end, from, to count(*) as StatusTotal FROM demo WHERE end is null and (from='" & xlocation &"' or to='" & xlocation &"') group by fromloc, toloc"

Open in new window

sasha85Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
Assuming your actual fieldnames are from and to, the group By clause should also use the same names

mySQL8="SELECT from, to, count(*) as StatusTotal FROM demo WHERE end is null and (from='" & xlocation & "' or to='" & xlocation &"') group by from, to"
 

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbizupCommented:
Also use brackets to differentiate the From field from the From keyword:

="SELECT [from], [to], count(*) as StatusTotal FROM demo WHERE [end] is null and ([from]='" & xlocation & "' or [to]='" & xlocation &"') group by [from], [to]"
0
Doc_McAlisterCommented:
Are "from" and "to" actual column names? Because when you use "group by" you can only have columns in your select that are either grouped by, or computed from the grouping.  So if you group by "fromloc" and "toloc" then you can Select "fromloc" and "toloc" but not "from" and "to".

I am assuming that the columns are fromloc and toloc, not from and to.  I am also assuming that you want to match "xlocation", not " xlocation ".

Set @xlocation = 'Colorado'

Select fromloc, toloc, count(*) As 'Status Total'
From demo
Where end is null
   And ( fromloc like '%@xlocation%' Or toloc like '%@xlocation%' )
Group By fromloc, toloc

You can replace the "like"s with =  and remove the %'s if you don't need a pattern match.
0
Doc_McAlisterCommented:
You can not select the "end" column without putting it in the group by clause.  But you have no need to as you are only getting the Nulls in the where clause.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.