title: SQL: how to select rows with values equal to thousand (1 column may contain several values)
body: <p>Would you help me, please, to select the rows which contain at least 1 value between 1000 and 1999.
  The column I have (nvarchar(255):</p>
  
  <p>col1</p>
  
  <pre><code>5501, 3500
  3001, 3050, 4020
   1030, 1010, 1043, 2000
   3010, 1420, 8000, 2044
   1330, 1330, 8000, 3111
   1333, 1132, 8000, 1332
  </code></pre>
  
  <p>Desirable result:</p>
  
  <pre><code>1030, 1010, 1043, 2000
   3010, 1420, 8000, 2044
   1330, 1330, 8000, 3111
   1333, 1132, 8000, 1332
  </code></pre>
  
  <p>I've tried to use self written function splitstring:</p>
  
  <pre><code>ALTER FUNCTION [dbo].[fn_splitstring] ( @stringToSplit VARCHAR(MAX) )
  RETURNS
   @returnList TABLE ([Name] [nvarchar] (500))
  AS
  BEGIN
  
   DECLARE @name NVARCHAR(255)
   DECLARE @pos INT
  
   WHILE CHARINDEX(',', @stringToSplit) &gt; 0
   BEGIN
    SELECT @pos  = CHARINDEX(',', @stringToSplit)  
    SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1)
  
    INSERT INTO @returnList 
    SELECT @name
  
    SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+1, LEN(@stringToSplit)-@pos)
   END
  
   INSERT INTO @returnList
   SELECT @stringToSplit
  
   RETURN
  END
  </code></pre>
  
  <p>and <code>string_agg()</code>
  but it works only with the single row.</p>
  
  <p>Thank you very much.</p>