I have a couple of tables that can only be accessed using sybase. I need to write a query that will extract data from July to a date parameter specified (eg. 201507 - 201512). Once the date parameters has been inputted, I need to access tables on sybase with the names: ff_vv_201507_tt to ff_vv_201512_tt.
I though of perhaps having the yyyymm as a variable. I am not sure how to implement this as I am pretty new to SQL.
I have tried accessing one table from sybase but my code did not seem to work:
DECLARE @Table_Name sysname, @DynamicSQL nvarchar(4000)
SET @Table_Name = 'ff_vv_201507_tt'
SET @DynamicSQL = 'select
*
FROM OPENQUERY(SADATABASE, 'select
*
from ' @Table_Name '
)''
EXECUTE sp_executesql @DynamicSQL
Your help would be greatly appreciated.
Thank you