sql server - Why are my variables do not change their values? -


i'm writting big procedure in t-sql dynamic elements. make short post important codelines.

declare....  begin  while @start <= @rowcount begin   print @start   print @rowcount    set @sqlval = 'select @zwischen1 = @currentcolumn_val1                  z_skm                  id = @startid';    set @parmdefinitionval = n'@currentcolumn_val1 nvarchar(500),                              @startid int,                              @zwischen1 nvarchar(50) output';    exec sp_executesql     @sqlval,     @parmdefinitionval,     @currentcolumn_val1 = @currentcolumn_val,     @startid = @start,     @zwischen1 = @currentval output;    print @currentval     set @sqlkey ='select @zwischen2 = @currentcolumn_key1                 z_skm                 id = @startid';    set @parmdefinitionkey = n'@currentcolumn_key1 nvarchar(500),                              @startid int,                              @zwischen2 nvarchar(50) output';    exec sp_executesql     @sqlkey,     @parmdefinitionkey,     @currentcolumn_key1 = @currentcolumn_key,     @startid = @start,     @zwischen2 = @currentkey output;    print @currentkey    set @start = @start + 1   print'loop-end'  end  end go 

my problem is, prints same values. , values ones passed @ @parmdefinitionkey , @parmdefinitionval @currentcolumn_key1 , @currentcolumn_val1.

i hope guys can out.

edit:

now works. here change in code :

set @sqlval = 'select @zwischen1 = '+@currentcolumn_val+' z_skm id = @startid'; set @parmdefinitionval = n'@startid int,@zwischen1 nvarchar(50) output' ; exec sp_executesql @sqlval,@parmdefinitionval,@startid=@start,@zwischen1=@currentval output;    set @sqlkey ='select @zwischen2 = '+@currentcolumn_key+' z_skm id = @startid'; set @parmdefinitionkey=n'@startid int, @zwischen2 nvarchar(50) output'; exec sp_executesql @sqlkey,@parmdefinitionkey,@startid=@start,@zwischen2=@currentkey output; 

i dont know why, looks not possible pass dynamic_column via argument execute, needed placed string before.. made absolutely no sense me.

try change queries this,

set @sqlval = 'select '+@zwischen1+' = '+@currentcolumn_val1+'                  z_skm                  id = '+@startid; 

i think @zwischen1 variable hold column name


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -