Ver Mensaje Individual
  #20 (permalink)  
Antiguo 06/09/2012, 10:18
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Incrementar un campo desde un trigger

so? como tienes un a,b,c,d,e,f,g en un datetime? pon tus datos reales para poder ayudarte :S porque el rank como te lo dieron funciona cuando los valores de campos 2 son a,b,c,d....

digamos que tienes esto:

Código SQL:
Ver original
  1. DROP TABLE #t1
  2. CREATE TABLE #t1 (campo1 VARCHAR(10), campo2 datetime)
  3. INSERT INTO #t1 VALUES ('1',getdate())
  4. INSERT INTO #t1 VALUES ('1',getdate())
  5. INSERT INTO #t1 VALUES ('1',getdate())
  6. INSERT INTO #t1 VALUES ('2',getdate())
  7. INSERT INTO #t1 VALUES ('1',getdate())
  8. INSERT INTO #t1 VALUES ('2',getdate())
  9. INSERT INTO #t1 VALUES ('1',getdate())
  10. INSERT INTO #t1 VALUES ('1',getdate())
  11. INSERT INTO #t1 VALUES ('1',getdate())
  12. GO
  13.  
  14. SELECT dense_rank() OVER (ORDER BY campo1) AS id,
  15. campo1,
  16. campo2
  17. FROM #t1

entonces usamos dense rank para sacar lo que necesitas :S, chica ayudame a ayudarte :S
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me