Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CTE issue

Author  Topic 

musclebreast
Yak Posting Veteran

77 Posts

Posted - 2012-08-15 : 15:28:23
HI,

@visakkh16...I'll asnwer my other mail later or tomorrow:)

I've got just a little issue with a CTE..I want create some temporarly table which i can use...I need two..one with the last day of each month...and another with the last day of a quarter




;WITH testtable(test)


AS (
select '31/01/'

union all

select '28/02/'

union all

select '31/03/'

union all

select '30/04/'

union all

select '31/05/'

union all

select '30/06/'

union all

select '31/07/'

union all

select '31/08/'

union all

select '30/09/'

union all

select '31/10/'

union all

select '30/11/'

union all

select '31/12/'

), months(date1)



AS (
select '31/03/'

union all

select '30/06/'

union all

select '30/09/'

union all

select '31/12/'

), quarters(date1)



AS (
select test from testtable
)


select * from months



now when I do the select on table month...I get all values from table quarter...

Does anybody know why?

Kind regards,

Lara

musclebreast
Yak Posting Veteran

77 Posts

Posted - 2012-08-15 : 17:14:54
Hi,

I got it..hopefully....I did it as follows:



;WITH months(date)


AS (
select '31/01/'

union all

select '28/02/'

union all

select '31/03/'

union all

select '30/04/'

union all

select '31/05/'

union all

select '30/06/'

union all

select '31/07/'

union all

select '31/08/'

union all

select '30/09/'

union all

select '31/10/'

union all

select '30/11/'

union all

select '31/12/'

),



quarters(date)

AS (
select '31/03/'

union all

select '30/06/'

union all

select '30/09/'

union all

select '31/12/'

)

select * from quarters


it works..would you say it's a correct way?

Kind regards,

Lara
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-15 : 22:57:23
where are the year parts?



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

musclebreast
Yak Posting Veteran

77 Posts

Posted - 2012-08-16 : 06:57:14
I added these, as I did it for month and days...have it tested alot..and it seems working without any error.

Kind regards,

Lara
Go to Top of Page
   

- Advertisement -