Ver Mensaje Individual
  #4 (permalink)  
Antiguo 02/05/2013, 15:42
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 6 meses
Puntos: 774
Respuesta: select 7 dias de los ultimos 30

sip con un left join y haciendo un datediff :)


algo asi:


Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. id INT IDENTITY(1,1),
  4. dato VARCHAR(20),
  5. fecha datetime
  6. )
  7.  
  8. INSERT INTO #temp VALUES ('yo',GETDATE())
  9. INSERT INTO #temp VALUES ('tu',dateadd(dd,1,GETDATE()))
  10. INSERT INTO #temp VALUES ('el',dateadd(dd,2,GETDATE()))
  11. INSERT INTO #temp VALUES ('nosotros',dateadd(dd,3,GETDATE()))
  12. INSERT INTO #temp VALUES ('ustedes',dateadd(dd,4,GETDATE()))
  13. INSERT INTO #temp VALUES ('ellos',dateadd(dd,5,GETDATE()))
  14. INSERT INTO #temp VALUES ('aquellos',dateadd(dd,7,GETDATE()))
  15.  
  16. SELECT t1.id,t1.dato,CASE WHEN isnull(t2.fecha,0)=0 THEN 'No data' ELSE CONVERT(VARCHAR(20),t2.fecha,101) END AS diff FROM #temp AS t1
  17. LEFT JOIN (SELECT * FROM #temp WHERE DATEDIFF(dd,getdate(),fecha)>=1 AND DATEDIFF(dd,getdate(),fecha)<=3) AS t2 ON (t1.id=t2.id)

ya nada mas adecualo a tus necesidades
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me