Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SQL in Colfusion

Status
Not open for further replies.

jjmew

Programmer
Aug 20, 2002
34
0
0
US
I have this query runing and i need to use the value that his query returns, How i can do use it? how i can refer to that value?

<cfquery name=&quot;numofemp&quot; datasource=&quot;#Datasource#&quot; username=&quot;#DBUSER#&quot; password=&quot;#DBPASS#&quot;>

select max(STAFF_ID) from Staff
</cfquery>
 
SELECT max(staff_id) as total
FROM staff

<cfoutput query=&quot;numofemp&quot;>
#total#
</cfoutput>
 
You might want to think about counting the staff this way:
Code:
SELECT COUNT(staff_id) AS TotalStaff
Down the road, if staff members get deleted, you won't get the right count since you'll always be getting the max(staff_id) and not the true count.

For example:

You have 10 employees:

staff_id
1
2
3
4
5
6
7
8
9
10

Employees 3 and 7 get deleted... Now you have 8. If you were to get the max(staff_id) you would get a false return value of 10, but in reality you have two less than that.

Just something to think about...

-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top