Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this result is needed

gft.dbo.GFT_Jan14
gft.dbo.GFT_Dec13
gft.dbo.GFT_Nov13
gft.dbo.GFT_Oct13
gft.dbo.GFT_Sep13

my query is as below

SQL
DECLARE @qry VARCHAR(max)
DECLARE @tab1 VARCHAR(max)
DECLARE @tab2 VARCHAR(max)
DECLARE @tab3 VARCHAR(max)
DECLARE @tab4 VARCHAR(max)
DECLARE @tab5 VARCHAR(max)
DECLARE @stvar VARCHAR(50)

SET @stvar = 'gft.dbo.GFT_'
SET @tab1 = @stvar + left(DATENAME(MONTH, GETDATE() - 1), 3) + right(YEAR(getdate() - 1), 2)
SET @tab2 = @stvar + left(DATENAME(MONTH, GETDATE() - 35), 3) + right(YEAR(getdate() - 35), 2)
SET @tab3 = @stvar + left(DATENAME(MONTH, GETDATE() - 70), 3) + right(YEAR(getdate() - 70), 2)
SET @tab4 = @stvar + left(DATENAME(MONTH, GETDATE() - 100), 3) + right(YEAR(getdate() - 100), 2)
SET @tab5 = @stvar + left(DATENAME(MONTH, GETDATE() - 130), 3) + right(YEAR(getdate() - 130), 2)


problem is while fixing days 1,35, 70, 100, 130
can anyone tell me how use months instead of days so that feburary and 31st 30th days can be auto adjusted??

somthing like this logic can be used and how??

set @tableName= 'gft.dbo.GFT_' + 'Month(getdate() - 1 month)
set @tableName= 'gft.dbo.GFT_' + 'Month(getdate() - 2 months)
set @tableName= 'gft.dbo.GFT_' + 'Month(getdate() - three months)
Posted
Comments
Maciej Los 28-Feb-14 16:20pm    
Not clear! Please, be more specific and provide more details.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900