SQLTeam.com | Weblogs | Forums

SQL Query help

This post was flagged by the community and is temporarily hidden.

hi

please see create data sample script ...

meant for any "experts" to find solution quickly
who will not do "SQL" without sample data

:slight_smile: :slight_smile:

please click arrow to the left for "drop create data"
DROP TABLE #data 

go 

CREATE TABLE #data 
  ( 
     [date]     DATE, 
     segment1   VARCHAR(1), 
     deportdate DATE 
  ) 

go 

; 
WITH tally_cte 
     AS (SELECT N=0 
         UNION ALL 
         SELECT n + 1 
         FROM   tally_cte 
         WHERE  n + 1 < 32) 
INSERT INTO #data 
SELECT Cast(Dateadd(day, n, '1/1/2016') AS DATE), 
       'A', 
       CASE 
         WHEN Cast(Dateadd(day, n, '1/1/2016') AS DATE) = '1/6/2016' THEN 
         '1/6/2016' 
         WHEN Cast(Dateadd(day, n, '1/1/2016') AS DATE) = '1/13/2016' THEN 
         '1/13/2016' 
         WHEN Cast(Dateadd(day, n, '1/1/2016') AS DATE) = '1/18/2016' THEN 
         '1/18/2016' 
         WHEN Cast(Dateadd(day, n, '1/1/2016') AS DATE) = '1/20/2016' THEN 
         '1/20/2016' 
         WHEN Cast(Dateadd(day, n, '1/1/2016') AS DATE) = '1/25/2016' THEN 
         '1/25/2016' 
         WHEN Cast(Dateadd(day, n, '1/1/2016') AS DATE) = '1/28/2016' THEN 
         '1/28/2016' 
       END 
FROM   tally_cte 

go 

SELECT 'sample data',* 
FROM   #data 

go

This post was flagged by the community and is temporarily hidden.

This post was flagged by the community and is temporarily hidden.