• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 49
  • Last Modified:

How can I pull of this query?

This works:

select DISTINCT DP.int_DEVELOPERS_Tool_Id as project_rank from net_BudgetTools..tbl_DEVELOPERS_Projects DP

Thing is, I want to list them by their project_rank_id.

I've done this before, but I've forgotten how. How can I list these distinct values according to their project_rank_id? What would that select statement look like?

Thanks!
0
brucegust
Asked:
brucegust
  • 4
1 Solution
 
brucegustPHP DeveloperAuthor Commented:
OK, I've been working and I've got this to work...

$sql="select DP.int_DEVELOPERS_Tool_Id, DPS.int_DEVELOPERS_ProjectStatus_Id as status_id from net_BudgetTools..tbl_DEVELOPERS_Projects DP
LEFT JOIN
net_BudgetTools..tbl_DEVELOPERS_ProjectStatuses      DPS      
ON DP.int_DEVELOPERS_ProjectStatus_Id = DPS.int_DEVELOPERS_ProjectStatus_Id AND DPS.bit_Is_Active = 1";

...but when I do this:

$sql="select DP.int_DEVELOPERS_Tool_Id, DPS.int_DEVELOPERS_ProjectStatus_Id as status_id from net_BudgetTools..tbl_DEVELOPERS_Projects DP
LEFT JOIN
net_BudgetTools..tbl_DEVELOPERS_ProjectStatuses      DPS      
ON DP.int_DEVELOPERS_ProjectStatus_Id = DPS.int_DEVELOPERS_ProjectStatus_Id AND DPS.bit_Is_Active = 1
GROUP BY
DP.int_DEVELOPERS_Tool_Id";

I get an error that reads as follows:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 8120 General SQL Server error: Check messages from the SQL Server [8120] (severity 16) [select DP.int_DEVELOPERS_Tool_Id, DPS.int_DEVELOPERS_ProjectStatus_Id as status_id from net_BudgetTools..tbl_DEVELOPERS_Projects DP LEFT JOIN net_BudgetTools..tbl_DEVELOPERS_ProjectStatuses DPS ON DP.int_DEVELOPERS_ProjectStatus_Id = DPS.int_DEVELOPERS_ProjectStatus_Id AND DPS.bit_Is_Active = 1 GROUP BY DP.int_DEVELOPERS_Tool_Id]' in /var/www/html/testsite/c0gusb1/mssql_class.php:19 Stack trace: #0 /var/www/html/testsite/c0gusb1/mssql_class.php(19): PDO->query('select DP.int_D...') #1 {main} thrown in /var/www/html/testsite/c0gusb1/mssql_class.php on line 19  

The select statement works fine and it would seem to be that "GROUP" is what I need, yet I can't implement without getting an error. What am I doing wrong?
0
 
brucegustPHP DeveloperAuthor Commented:
Also, I'm querying a MSSQL database, if that makes any difference.
0
 
InsoftserviceCommented:
Please provide the table schema with few data so that it would be easy for us to provide you with correct sql statements
0
 
brucegustPHP DeveloperAuthor Commented:
I don't have it, but your suggestion confirms the fact that I need to reach out to my .NET counterpart and get that schema because the error messages by themselves don't really help.

I'll get back with you.
0
 
brucegustPHP DeveloperAuthor Commented:
insoftservice - I'm going to award you the points, simply because you took the time to respond.

I did get with my .NET counterpart and was able to access MSSMS which gave me a the chance to see the database and proof my code.

The problem was remedied by establishing a new connection. I was running a separate select statement within a loop. Turned out to be problematic, in that I was attempting to another query within the same connection. Never encountered that before, but once I opened up a new connection, the whole thing came together!

Thanks for your input!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now