I need to generate a report in access using dynamic sql. The user will be prompted to enter a county name when generating the report. I need to use this county name to drive which database and table I will be using to retrieve the dataset from. the sql version of this query is as follows. note the county is hardcoded in this example. I know how to make the report prompt the user for the county, but I cant get the correct syntax that access likes. btw, these are all sql tables we are using through access. any help is appreciated...
DECLARE @COUNTY VARCHAR(25)
declare @dbase varchar(max)
DECLARE @TBLNAME VARCHAR(40)
DECLARE @sql VARCHAR(MAX)
set @COUNTY = 'RICHLAND'
SET @dbase ='SC_' + @COUNTY + '_SRC'
SET @TBLNAME = 'dbo.' + @COUNTY + '_TRANSLATION'
SET @sql='SELECT *
FROM ' + @dbase +'.'+@TBLNAME
EXECUTE(@sql)
DECLARE @COUNTY VARCHAR(25)
declare @dbase varchar(max)
DECLARE @TBLNAME VARCHAR(40)
DECLARE @sql VARCHAR(MAX)
set @COUNTY = 'RICHLAND'
SET @dbase ='SC_' + @COUNTY + '_SRC'
SET @TBLNAME = 'dbo.' + @COUNTY + '_TRANSLATION'
SET @sql='SELECT *
FROM ' + @dbase +'.'+@TBLNAME
EXECUTE(@sql)