views:

520

answers:

2

Hi everybody,

I'm having a problem with an sql query that i use for my mobile application which uses sql server 2005 ce. I'm not so good with t-sql, so have a problem with this query

SELECT TP.ID_TASK_MASTER, TP.ID_PROBLEM, TP.ID_TASK_PROBLE, P.DS_PROBLEM, 
       TP.SW_HASOK, TP.SW_HASNOK, TP.SW_HASTOK, TP.SW_HASVALUE,  
       TP.NO_VALUE1, TP.NO_VALUE2 
FROM TASK_PROBLEMS TP 
  INNER JOIN PROBLEMS P 
    ON TP.ID_PROBLEM = P.ID_PROBLEM  
GROUP BY P.DS_PROBLEM,TP.ID_TASK_MASTER, TP.ID_PROBLEM, TP.ID_TASK_PROBLE 
HAVING TP.ID_TASK_MASTER = @P_IDTASKMASTER

What i try to do is doing a group by on ds_problem field, getting an error like this :

{"In aggregate and grouping expressions, the SELECT clause can contain only aggregates and grouping expressions. [ Select clause = TP,SW_HASOK ]"}

So what i made wrong? Thanks..

+1  A: 

I suppose what you meant to do was

SELECT TP.ID_TASK_MASTER, TP.ID_PROBLEM, TP.ID_TASK_PROBLE, P.DS_PROBLEM, 
       TP.SW_HASOK, TP.SW_HASNOK, TP.SW_HASTOK, TP.SW_HASVALUE,  
       TP.NO_VALUE1, TP.NO_VALUE2 
FROM TASK_PROBLEMS TP 
  INNER JOIN PROBLEMS P 
    ON TP.ID_PROBLEM = P.ID_PROBLEM  
WHERE TP.ID_TASK_MASTER = @P_IDTASKMASTER
ORDER BY P.DS_PROBLEM,TP.ID_TASK_MASTER, TP.ID_PROBLEM,TP.ID_TASK_PROBLE
Glenner003
A: 

Actually no, what i want to do is having all the ds_problems grouped, like in the db datas like this:

TASK_PROBLEMS: test1 test2 test1 test2 test1 test2 test1

But what i want is this:

TASK_PROBLEMS test1 test2

thats all, group all the test1s and test2s

mehmetserif