Declare @table table
(
Col1 varchar(50),
Col2 varchar(50)
)
insert into @table
select '100', '*10+2'
select Col1 + '' + Col2
from @table
预期输出为:1002
你能帮忙吗?
答案 0 :(得分:1)
Use EXEC SQL query :
Declare @table table
(
Col1 varchar(50),
Col2 varchar(50)
)
DECLARE @Cal VARCHAR(100)
insert into @table
select '100' , '*10+2'
SELECT @Cal = Col1+''+Col2 from @table
SELECT @Cal = 'SELECT (' + @Cal + ')'
EXEC (@Cal)
答案 1 :(得分:1)
像这样使用:
Declare @table table
(
Col1 varchar(50),
Col2 varchar(50)
)
Declare @Out varchar(100),@Query varchar(100)=''
insert into @table
select '100', '*10+2'
select @Out= Col1 + '' + Col2
from @table
SET @Query = 'SELECT ' +@Out
EXEC (@Query)