You can build SQL string and run it with EXECUTE command or sp_executesql system sproc. For example,
USE pubs
Declare @lcTablename Varchar(30), @SqlStr nvarchar(256)
Set @lcTableName = 'Sales'
SET @SqlStr = 'SELECT * FROM sales'
EXECUTE(@SqlStr)
>Hi All:
> Is there a way I can create a macro in SQL?
>For Example
>This is what I want to do.
>
>Declare @lcTablename Varchar(30)
>Set @lcTableName = (Select Name from cSetUp0
>
>Select * From @lcTableName
>
>@lcTableName varries depending on the situations. I do not want to issue the same code everytime. I want to store the table name in @lcTablename, just like vfp.
>
>Thanks
>MA
--sb--