Ver Mensaje Individual
  #6 (permalink)  
Antiguo 14/10/2004, 18:30
Avatar de u_goldman
u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 4 meses
Puntos: 98
Obtiene el máximo valor de un campo campo en "x" tabla, se necesita una conexión activa (en negritas), si es fin de archivo (EOF), regresa un 0

Código:
<%
Function GetMyMaxId(table, field)
	Set rsGetMyMaxId = Server.CreateObject("ADODB.Recordset")
	strSQLGetMyMaxId = "SELECT MAX(" & field & ") AS myMax FROM " & table
	rsGetMyMaxId.Open strSQLGetMyMaxId, ObjConn, 3, 3
	fnctMyMaxId = rsGetMyMaxId("myMax")
	If IsNull(fnctMyMaxId) Then
		fnctMyMaxId = 0
	End If
	rsGetMyMaxId.Close
	Set rsGetMyMaxId = Nothing
	GetMyMaxId = fnctMyMaxId
End Function
%>
Llamada a la función
Cita:
MaxID = GetMyMaxId("tabla", "campo")
Salu2,
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway

Última edición por u_goldman; 15/10/2004 a las 10:44