You can split the comments column to lines and select the line of
interest. Here is one example (the table master..spt_values simulates
auxiliary table with numbers):
CREATE TABLE TableX (
foo_key INT PRIMARY KEY,
foo_name VARCHAR(30),
foo_comment VARCHAR(250));
INSERT INTO TableX
VALUES(1, 'name1', 'line1' + CHAR(13) + CHAR(10) +
'line2' + CHAR(13) + CHAR(10) +
'line3');
SELECT foo_key, foo_name, comment_line_text, comment_line
FROM (
SELECT SUBSTRING(foo_comment, n,
CHARINDEX(CHAR(13) + CHAR(10),
foo_comment + CHAR(13) + CHAR(10), n)
- n) AS
comment_line_text,
n + 1 - LEN(REPLACE(LEFT(foo_comment, n), CHAR(13) +
CHAR(10), '
' )) AS comment_line,
foo_key, foo_name
FROM TableX AS F
CROSS JOIN
(SELECT number
FROM master..spt_values
WHERE type = 'P'
AND number BETWEEN 1 AND 250) AS Nums(n)
WHERE SUBSTRING(CHAR(13) + CHAR(10) + foo_comment, n, 2) = CHAR(13) +
CHAR(10)
AND n < LEN(foo_comment) + 2) AS T
WHERE comment_line = 2;
HTH,
Plamen Ratchev
http://www.SQLStudio.com