title: Indirectly print the value of scalar variable - Tsql
body: <p>It seems a little nasty but I am wondering if it is possible. Actually I want to print values of several variables. I can write print statement multiple times but instead of this I am thinking to use a while loop and write one single statement that can print the values of all the variables one by one.</p>
  
  <p>This is what I am thinking: </p>
  
  <pre><code>declare @test as nvarchar(4)
  select @test  = 'test'
  
  declare @test1 as int
  select @test1 = 1234
  
  print '@'+@test+'1' 
  </code></pre>
  
  <p>the statement  <code>print '@'+@test+'1'</code> prints <code>@test1</code> which is OK. But what I am looking for is, if I can get the value of <code>@test1</code> using the same statement. </p>
  
  <p>I hope so I am clear enough to say what I mean. </p>