title: Variable store data field value in sql query
body: <pre><code>Declare @string nvarchar(20)
  set @string=(select [Bill Period] from [sqldata].[dbo].[jun1])
  select substring (@string,1,3)
  </code></pre>
  
  <p>i got just single value from the entire column [Bill period],i want all the record from [Bill Period] to @string but it is not working.</p>
  
  <p>how to increment table INDEX and fetch the records</p>
  
  <pre><code>declare @INDEX int
  set @INDEX=1
  while(@INDEX&lt;3)
  begin
  Declare @string nvarchar(20)
  set @string=(select [Bill Period] from [sqldata].[dbo].[jun1])
  select substring (@string,1,3)
  set @INDEX=@INDEX+1
  end
  </code></pre>