CTE and last known date processing

Posted by stackoverflowuser on Stack Overflow See other posts from Stack Overflow or by stackoverflowuser
Published on 2010-03-08T19:31:09Z Indexed on 2010/03/08 19:36 UTC
Read the original article Hit count: 283

Input
@StartDate = '01/25/2010'
@EndDate = '02/06/2010'

I have 2 CTEs in a stored procedure as follows:

with CTE_A as
(
   [gives output A..Shown below]
),
with CTE_B as
(
  Here,
  I want to check if @StartDate is NOT in output A then replace it with the last known date. In this case, since @startdate is less than any date in output A hence @StartDate will become 02/01/2010.

  Also to check if @EndDate is NOT in output A then replace it with the last known date. In this case, since @enddate is 02/06/2010 hence it will be replace with 02/05/2010.

  // Here there is a query using @startDate and @EndDate.

)

output A

Name   Date   
A      02/01/2010  
B      02/01/2010  
C      02/05/2010  
D      02/10/2010 

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql