Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

no repetir registro

Estas en el tema de no repetir registro en el foro de SQL Server en Foros del Web. Hola estimados colegas, bueno vengo ante a ustedes a exponer mi pequeño problema, lo que pasa es que tengo la siguiente consulta : Código: Set ...
  #1 (permalink)  
Antiguo 20/08/2008, 09:26
Avatar de ejesus  
Fecha de Ingreso: julio-2008
Mensajes: 26
Antigüedad: 15 años, 10 meses
Puntos: 0
no repetir registro

Hola estimados colegas, bueno vengo ante a ustedes a exponer mi pequeño problema, lo que pasa es que tengo la siguiente consulta :

Código:
Set oConn = Server.CreateObject("ADODB.Connection")
	Set rs = CreateObject("ADODB.Recordset")
	oConn.open db,"",""
	set ds = Server.CreateObject("ADODB.Recordset")
sql =" select vchMatricula from tblAspirantes where vchMatricula = '"&matricula&"' "
	
Set res = oConn.Execute ( sql )
	
if(res.fields("vchMatricula") < 0) then

sql = "insert into tbl_SIAT_HistorialAlumno (vchMatricula, dtFechaHoy, vchReligion, vchOcupacion, vchSangre, vchEscolaridad, chAboPvivo, chAboPedad, chAboPsano, vchAboPenfermo,chAbaPvivo, chAbaPedad, chAbaPsano, vchAbaPenfermo, chAboMvivo, chAboMedad, chAboMsano, vchAboMenfermo, chAbaMvivo, chAbaMedad,chAbaMsano, vchAbaMenfermo, chPatvivo, chPatedad, chPatsano, vchPatenfermo, chMatvivo, chMatedad, chMatsano, vchMatenfermo, chHe1vivo,chHe1edad, chHe1sano, vchHe1enfermo, chHe2vivo, chHe2edad, chHe2sano, vchHe2enfermo, chHe3vivo, chHe3edad, chHe3sano, vchHe3enfermo,chT1vivo, chT1edad, chT1sano, vchT1enfermo, chT2vivo, chT2edad, chT2sano, vchT2enfermo, chT3vivo, chT3edad, chT3sano, vchVeces1, vchVeces2,vchVeces3, vchVeces4, vchVeces5, vchVeces6, vchVeces7, vchVeces8, vchVeces9, vchVeces10, vchVeces11, chBanoD, chAseoB, chLavadoM,chCambioR, vchComidas, vchT3enfermo, vchVacuna1, vchDosis1, vchDosis2, vchDosis3, vchVacuna2, vchDosis4, vchDosis5, vchDosis6,vchVacuna3, vchDosis7, vchDosis8, vchDosis9, vchVacuna4, vchDosis10, vchDosis11, vchDosis12, vchAlcohol, vchFrecuencia, vchCantidad,chBebidas, vchFechaAlcohol, vchPorqueAlcohol, chFumar, vchCigarrillos, vchTipo, chTipoCigarro, vchFechaCigarro,vchToxicomanias, chCasa, vchHabitaciones, vchHabitan, vchDuermen, vchCama, vchRopa, chMatCasa, chMatTecho, chMatPiso, chTipoAgua, chAnimales, vchCualesAnimales, chSexuales,chEdadIniciaste, vchFrecuenciaSexo, chSexPareja, chProteccion, vchCualProteccion, chElectrica, chAguaPotable,chDrenaje,chIntervenido, vchDequeInt, vchFechasInt, chComplicaciones, chTipoCompli, chTransfundido, vchDequeTransfundido,vchFechasTransFunciones, vchMotivos, chcompliTrans, chTipoCompli1, chReaccion, vchPresentoReac, chMedicamentos, vchCualMed,chAlimentos, vchCualAlim, chSustancias, vchCualSustancias, vchManifesto, chVaricela, chRubeola, chSarampion, chPaperas, chHepatitis, chTifoidea,vchFechaMestruacion, vchFrecuenciaMest, vchDiasMest, vchTipoSangrado, vchTipoDolor, vchIncapacita, vchMedicamentos, vchQueMed, vchEmba, vchPart, vchAbort, vchCesarea, vchTiempoEmb, vchCursoEmbarazo, vchCompliEmba,vchAtendio, vchCantidadSang, vchCausasCesarea, vchUltimaMestruacion, vchSecreVaginal, vchColorVag, vchConsist, vchCantidadSecre,vchFreSecre, vchCuandoInicio, vchTratamiento, vchCualTratamiento, vchCualEnf1, vchCuandoEnf1, vchDiagnosEnf1, vchControlEnf1, vchDosisEnf1,vchAdminEnf1, vchCompliEnf1, vchCualEnf2, vchCuandoEnf2, vchDiagnosEnf2, vchControlEnf2, vchDosisEnf2, vchAdminEnf2, vchCompliEnf2, chDifRes, chTosRes, chEsTosRes, chPechoRes, chEspaldaRes, chDolorRes, chMoradoRes, chDig1, chDig2, chDig3, chDig4, chDig5, chDig6, chDig7,chDig8, chDig9, chDig10, chDig11, chDig12, chDig13, vchDig14, chDig15, chDig16, chDig17, vchDig18, chDig19, vchDig20, chDig21, chDig22, chDig23,chDig24, chDig25, vchDig26, vchDig27, chDig28, chDig29,chDig30, chDig31, chCic1, chCic2, chCic3, chCic4, chCic5, chCic6, vchCic7, chCic8, chCic9,vchCic10, chCic11, chCic12, vchCic13, chCic14, chCic15, chCic16, chCic17, chCic18, chCic19, chCic20, chCic21, chCic22, chCic23, chLast, vchLast1,vchLast2, vchLast3, chLast4, chLast5, chLast6, chLast7, chLast8, chLast9, chLast10, chLast11, chLast12, chLast13, chLast14, chLast15, chLast16,chLast17, chLast18, chLast19, chLast20, chCicColor, chLastAsiento, vchFrecuenciaCama) values ('"&matricula&"','"&Date()&"','"&religion&"','"&ocupacion&"','"&sangre&"','"&escolaridad&"','','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""','""')"

else
sql="update tbl_SIAT_HistorialAlumno set vchMatricula='"&matricula&"', dtFechaHoy='"&Date()&"', vchReligion='"&religion&"', vchOcupacion='"&ocupacion&"', vchSangre='"&sangre&"', vchEscolaridad='"&escolaridad&"' where vchMatricula = '"&matricula&"' "
end if 

Set rs = oConn.Execute ( sql )

segun yo en mi poco experiencia, lo que intento hacer es que si ya hay un registro en la base de datos no lo repita, es decir si vchMatricula.value ya existe en la base de datos que no la repita si no que actualice sobre ella
pero no me sale .

podrian ayudarme porfavor gracias.
  #2 (permalink)  
Antiguo 20/08/2008, 09:31
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
Respuesta: no repetir registro

Seria mejor hacerlo con un stored procedure donde incluyas todo: la cuenta, insercion y actualizacion...

pero ahi en tu code, lo que podrias hacer es cambiar

select vchMatricula

por

select count(1) as cuenta


y


if(res.fields("vchMatricula") < 0) then

por

if(res.fields("cuenta") = 0) then



--

como dije hacerlo con un sp es lo mejor, manejando comandos en el front para pasar los parametros...


Saludos!
__________________
La sencillez y naturalidad son el supremo y último fin de la cultura...
--
MCTS : SQL Server 2008, .NET Framework 3.5, ASP.NET Applications.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:28.