Avatar of mavmanau
mavmanau
Flag for Australia

asked on 

SQL query in PHP - What is wrong my my query?

Hello Experts!

Thank you for taking the time to look at my question. Essentially I have the below query that is not working, and I can't see why.

SELECT BrandID,COUNT(CONVERT(VARCHAR(10),DateFunded,111)) as CNT,RiskLevelID count((if(BrandID==2,0)) FROM DB Where CONVERT(VARCHAR(10),DateFunded,111) is not NULL and CONVERT(VARCHAR(10),DateFunded,111) BETWEEN '2011/09/01' and '2011/09/30' group by CNT order by CONVERT(VARCHAR(10),DateFunded,111)

Essentially what I want to do, is given the data, I want it to group the data by the different dates and count it, - do I need to remove some of the other columns in order for that to happen?

This Query works fine, which gives me the sample date that follows after the query.

SELECT BrandID,CONVERT(VARCHAR(10),DateFunded,111),RiskLevelID FROM DB Where CONVERT(VARCHAR(10),DateFunded,111) is not NULL and CONVERT(VARCHAR(10),DateFunded,111) BETWEEN '2011/09/01' and '2011/09/30' order by CONVERT(VARCHAR(10),DateFunded,111)

Brand ID Date Funded Risk Level ID
PDP 2011/09/01 4
NZGC 2011/09/01 3
PDP 2011/09/02  
NZGC 2011/09/02 3
LP 2011/09/02 1
LP 2011/09/02 1
FSM 2011/09/03 3
PDP 2011/09/03 3
NSW 2011/09/03 3

Thank you very much for your assistance! it is much appreciated.
Microsoft SQL Server 2008PHP

Avatar of undefined
Last Comment
mavmanau

8/22/2022 - Mon