Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/04/2011, 13:17
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: Problema con instruccion sql

Prueba con algo asi :)

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. codigo INT,
  4. texto VARCHAR(200),
  5. conversacion INT,
  6. fecha datetime
  7. )
  8.  
  9. INSERT INTO #temp (codigo,texto,conversacion,fecha) VALUES (1,'Hola juan',1,getdate())
  10. INSERT INTO #temp (codigo,texto,conversacion,fecha) VALUES (2,'Hola jose',1,getdate())
  11. INSERT INTO #temp (codigo,texto,conversacion,fecha) VALUES (3,'bueno me voy',1,getdate())
  12. INSERT INTO #temp (codigo,texto,conversacion,fecha) VALUES (4,'Hola estas?',2,getdate())
  13. INSERT INTO #temp (codigo,texto,conversacion,fecha) VALUES (5,'si decime',2,getdate())
  14.  
  15. SELECT codigo,texto,conversacion,fecha, IDENTITY(INT,1,1) ROW INTO #temp2  FROM(
  16. SELECT ROW_NUMBER () OVER ( PARTITION BY conversacion ORDER BY conversacion ASC) AS RN, * FROM #temp
  17. ) t1 WHERE rn=1
  18.  
  19. SELECT ROW,texto,conversacion,fecha FROM #temp2

Saludos!!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me