Hello fellow porgrammers,
I have tried to resolve a problem in the VB forum that is giving me a really difficult time. The problem is a SQL query that uses a MAX function to retrieve a value in a table that holds employee numbers and other pertinent data that supports an application that I built.
In a nutshell, I have a sub-routine that is designed to access my SQL table and using this criteria return the highest employee number in a given company, there are three companies that I have to select from and then within that company the employee's names are grouped together based on thier last name, such as, if the last name is "L" then all employees with the last name starting with "L" is selected by my query.
Next the query should retrieve the highest employee number in that group so that the sub-routine can then increment that number by one and then it is added back to the table. So far it has not worked, some of the other programmers have tried to help but to no avail, I have gotten halfway thier but no cigar, no hitting the nail on the head, nothing...
Here is a sample of my query:
SELECT MAX(EIDNUM) AS MaxID, empLName, empComp,EIDNUM
FROM dbo.EmpHistory
WHERE (empComp = 'CCW') AND (empLName LIKE 'L%') AND
(EIDNUM NOT LIKE '199%')
GROUP BY empLName, empComp, EIDNUM
This query will return all of the employees whose last names begin with "L", I only want the employee number that is the highest number so that it can be incremented and assigned to a new employee. Any help that any of you can provide will be most appricated.
Thank You
JC
I have tried to resolve a problem in the VB forum that is giving me a really difficult time. The problem is a SQL query that uses a MAX function to retrieve a value in a table that holds employee numbers and other pertinent data that supports an application that I built.
In a nutshell, I have a sub-routine that is designed to access my SQL table and using this criteria return the highest employee number in a given company, there are three companies that I have to select from and then within that company the employee's names are grouped together based on thier last name, such as, if the last name is "L" then all employees with the last name starting with "L" is selected by my query.
Next the query should retrieve the highest employee number in that group so that the sub-routine can then increment that number by one and then it is added back to the table. So far it has not worked, some of the other programmers have tried to help but to no avail, I have gotten halfway thier but no cigar, no hitting the nail on the head, nothing...
Here is a sample of my query:
SELECT MAX(EIDNUM) AS MaxID, empLName, empComp,EIDNUM
FROM dbo.EmpHistory
WHERE (empComp = 'CCW') AND (empLName LIKE 'L%') AND
(EIDNUM NOT LIKE '199%')
GROUP BY empLName, empComp, EIDNUM
This query will return all of the employees whose last names begin with "L", I only want the employee number that is the highest number so that it can be incremented and assigned to a new employee. Any help that any of you can provide will be most appricated.
Thank You
JC