title: split the string and store it in three different variables in sql server
body: <p>I am using below function to split the string into multiple strings everything is working fine but i need to store the results into multiple variables </p>
  
  <p>instead of that the results are storing into a table </p>
  
  <p>this is my query </p>
  
  <pre><code>DECLARE @strngLen int
  DECLARE @split TABLE(siteId VARCHAR(100))
  
  DECLARE @city varchar(100), @state varchar(100), @zip varchar(100)
  
  SET @siteIds = 'OMAHA  NE  68117'
  
  SET @strngLen = CHARINDEX('  ', @siteIds)
  
  WHILE CHARINDEX('  ', @siteIds) &gt; 0
  BEGIN
      SET @strngLen = CHARINDEX('  ', @siteIds);
  
      INSERT INTO @split
      SELECT SUBSTRING(@siteIds,1,@strngLen - 1);
  
      SET @siteIds = SUBSTRING(@siteIds, @strngLen+1, LEN(@siteIds));
  END
  
  INSERT INTO @split
  SELECT @siteIds
  
  SELECT * FROM @split
  
  ---Here i need to store the @siteIds into multiple local variables 
  ---like in (@city varchar(100), @state varchar(100), @zip varchar(100)) 
  </code></pre>