You must use ORDER BY with TOP otherwise you can't expect consistent
results. Remember there is not first row unless you define it with ORDER BY.
Use UNION to avoid the need for a cursor:
CREATE TABLE Droit (col1 INTEGER, col2 INTEGER, col3 INTEGER, col4 INTEGER
/* Primary key not specified */ )
INSERT INTO DROIT VALUES (1,2,3,4)
SELECT 'COL1',col1 FROM
(SELECT TOP 1 *
FROM Droit
ORDER BY col1) c
UNION ALL
SELECT 'COL2',col2 FROM
(SELECT TOP 1 *
FROM Droit
ORDER BY col1) c
UNION ALL
SELECT 'COL3',col3 FROM
(SELECT TOP 1 *
FROM Droit
ORDER BY col1) c
UNION ALL
SELECT 'COL4',col4 FROM
(SELECT TOP 1 *
FROM Droit
ORDER BY col1) c
If you have a single column PK then you could avoid TOP with:
WHERE pkcol = (SELECT MIN(pkcol) FROM Droit)
Please include a CREATE TABLE statement and sample data as INSERT statements
with future posts.
--
David Portas
------------
Please reply only to the newsgroup
--
> Hello,
> I am trying to return a string that contains the first line of a table
> It must be something like
> field1 : Value1
> field2 : Value2
> ...
> fieldn : Valuen
> I do the following code but i can't return the Value (i also try with 2
> cursors without success)
> '
> DECLARE tnames_cursor CURSOR
> FOR
> SELECT Column_name
> FROM INFORMATION_SCHEMA.COLUMNS
> WHERE TABLE_NAME = 'DROIT'
> OPEN tnames_cursor
> BEGIN
> BEGIN
DROIT)
> END
> END
> CLOSE tnames_cursor
> DEALLOCATE tnames_cursor
> Thanks for your helf
> Franck