张
张丽敏
Unregistered / Unconfirmed
GUEST, unregistred user!
我试图在 FROM 后面跟表的变量. 如:
CREATE PROCEDURE DBO.tmp (@company char(2)) AS
declare @TABLE nchar
if @company = '01' set @TABLE = T1
if @company = '02' set @TABLE = T2
if @company = '03' set @TABLE = T3
...
SELECT * FROM @TABLE
GO
这样是不行的, 提示没定义@TABLE类型.
其实, 可以
if @cpmpany = '01' (select * from T1)
if @cpmpany = '02' (select * from T2)
但我这 select语句 较为复杂, 也不方便修改.
若能在 FROM 后面跟变量就较好看, 也易修改.
请求各位帮忙!!
CREATE PROCEDURE DBO.tmp (@company char(2)) AS
declare @TABLE nchar
if @company = '01' set @TABLE = T1
if @company = '02' set @TABLE = T2
if @company = '03' set @TABLE = T3
...
SELECT * FROM @TABLE
GO
这样是不行的, 提示没定义@TABLE类型.
其实, 可以
if @cpmpany = '01' (select * from T1)
if @cpmpany = '02' (select * from T2)
但我这 select语句 较为复杂, 也不方便修改.
若能在 FROM 后面跟变量就较好看, 也易修改.
请求各位帮忙!!