|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
This is the code.
SELECT [Why not workable].[SSN P ], [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ] FROM [Why not workable] WHERE [TXPD] <> (SELECT MIN(TXPD) FROM [Why not workable]) GROUP BY [SSN P] HAVING [SSN P] > 1 The field SSN P has multiple years. I am trying to list all the years except the first. Only when there are multiple years. I get this error message "You tried to execute a query that does not include the specified expression 'TXPD' as part of an aggregate function." TXPD is my tax year. Please help |
|
#2
|
||||
|
||||
|
Add the field to you GROUP BY statement.
Tips: 1) Remove the spaces in your field (column) names. 2) Try using alias for better readability. |
|
#3
|
|||
|
|||
|
SELECT [Why not workable].[SSN P ], [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ]
FROM [Why not workable] WHERE [TXPD] > (SELECT MIN(TXPD) FROM [Why not workable]) AND [SSN P] > (SELECT MIN([SSN P]) FROM [Why not workable]) GROUP BY [SSN P] HAVING COUNT (DISTINCT([SSN P])) > 1 This is a new version of the same code. The only error message that is being generated now is.... 'Undefined function 'Distinct' in expression'. Any suggestions? |
|
#4
|
||||
|
||||
|
You have to use the DISTINCT keyword in the SELECT part of the statement as in...
Code:
SELECT DISTINCT FieldName FROM Tablename |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|