好的,感谢您回答我的问题,但是看问题要复杂得多,因为我们正在运行一个动态 Sql,在 while 循环中形成查询然后将其存储在一个字符串变量中并运行它,问题是函数及时生成如下并附在下面。
create function ms_trafico.fn_mov_cambia_tag( in @num_celular char(20), in @str_comando char(120) )
returns char(120)
--on exception resume
as
begin
set nocount on
set temporary option string_rtruncation='OFF'
--aplican para isql
--set option isql_print_result_set=ALL
--set option isql_show_multiple_result_sets=On
declare @comando varchar(100)
declare @exec_qry varchar(500)
declare @cadena varchar(60)
declare @tag char(15)
declare @columna char(20)
declare @pos int
declare @strCadFinal char(150)
declare @strFono char(20)
set @comando = trim(@str_comando)
set @strFono = trim(@num_celular)
set @exec_qry='select XXX '
set @pos = 1
print "comando " + @comando
while(@pos <= locate(@comando,'<',-1))
begin
set @tag = substr(@comando,locate(@comando,'<',@pos),CHARINDEX('>', SUBSTR(@comando,locate(@comando,'<',@pos),length(@comando))))
set @pos = locate(@comando,'<',@pos) + 1
select atributo_campo into @columna from TB_MOV_MAPEO_COMANDOS where parametro = @tag
set @cadena="replace(XXX,'"||trim(@tag)||"',"||trim(@columna)||")"
set @exec_qry=replace(@exec_qry,'XXX',@cadena)
end
set @comando="'"||trim(@comando)||"'"
set @exec_qry=replace(@exec_qry,'XXX',@comando)
set @exec_qry=@exec_qry||' as comando INTO @strCadFinal FROM VM_ALL_SERVICES_MOVIL where num_celular=@strFono'
execute (@exec_qry)
return (@strCadFinal) "The result of my query with execute method"!!!!!!!!!!
end
go
谢谢你的关注。