问题描述
我想要查询存储在变量中的查询。 Query用于获取变量的给定值。我尝试使用exec命令但返回错误。我不知道怎么做
下面给出了SQL命令
这行用于生成所需的查询并存储到变量@mnvcSQL
select @mnvcSQL =''Select @ Prev = year''+ convert(varchar,cast((@ Field-1)as int))+''来自tblFinancialDistribution,其中ProjectId = ''+ cast(@pintProjectId as Varchar)+''和[lineno] =''+ cast(@mvcLineNoNetCashFlow as Varchar)
执行上面的行后,变量@mnvcSQL包含像SQL Sentance一样
从tblFinancialDistribution选择@ Prev = year4,其中ProjectId = 42并且[lineno] = - 29
我想要对此进行说明声明并希望在@Prev中得到结果值
I want to exicute a Query that stored in a variable. and the Query is used to get a given value to a variable. I tried to use exec command but that returns an error. i cant get an idea for how to do
the SQL commands are given bellow
This line is used to generate the required query and stored to a variable @mnvcSQL
select @mnvcSQL=''Select @Prev=year'' + convert(varchar,cast((@Field-1) as int))+ '' from tblFinancialDistribution where ProjectId='' + cast(@pintProjectId as Varchar)+ '' and [lineno]='' + cast(@mvcLineNoNetCashFlow as Varchar)
After Executing the above line the variable @mnvcSQL contain the the SQL Sentance like
Select @Prev=year4 from tblFinancialDistribution where ProjectId=42 and [lineno]=-29
I Want to exicute this statement and want the resulted value in @Prev
推荐答案
这篇关于如何执行存储过程中变量中存储的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!