We help IT Professionals succeed at work.
Get Started

php MSSQL query case

mavmanau
mavmanau asked
on
332 Views
Last Modified: 2012-06-27
Hello Experts,

thank you for taking a look at my question.

basically I have these 2 queries:
SELECT COUNT(Sta_Desc) FROM Full
Where Sta_Desc like 'SOff'
Or Sta_Desc like 'FSent'
And Lon_DateLoanAgreement between '2011-10-27' and '2011-10-28'
And Lgn_Name not like 'Cust Serv Repeat'
And Lgn_Name not like 'Cust Serv'

SELECT COUNT(Lon_DateLoanAgreement) FROM Full
Where Lon_DateLoanAgreement between '2011-10-27' and '2011-10-28'
And Lgn_Name not like 'Cust Serv Repeat'
And Lgn_Name not like 'Cust Serv'

that I wanted to combine.

I have done this:
$query = "SELECT count(case when (Sta_Desc like 'SOff') or (Sta_Desc like 'Fsent') then 1 else null end),COUNT(Lon_DateLoanAgreement) FROM Full
Where Lon_DateLoanAgreement between '2011-10-27' and '2011-10-28'
And Lgn_Name not like 'Cust Serv Repeat'
And Lgn_Name not like 'Cust Serv'";

but it is not quite working.  I know it is in the case somehow, but can't quite work it out.  The count is working for the second column I want, just not the first.  something to do with the or.  I have tried doing them as seperate ie fsent in one case, and soff as another but it doesn't do it.  I can do them as seperate queries and they work fine, but wanted to have them in one query!

Please help!!  any light you could shine on issue would be most appreciated!!

thank you very much!
Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE