take one table is t1 and in that column name is f1
f1 column values are
200
5000
3000
7000
300
600
100
400
800
400
i want display the values asc and desc in a single output.
sample output is
f1.a
100
200
300
400
500
600
etc......
and f1.d is
5000
4000
3000
2000
1000
etc...
Answer Posted / sumathy
Create table as 'f_order' with coulmn f1.
Run the following statement to get the above quesion's
results.
DECLARE @a INT, @b int
DECLARE @f1 CURSOR, @f2 CURSOR
Print 'Ascending '
SET @f1 = CURSOR FOR
SELECT f1
FROM f_order order by 1 asc
OPEN @f1
FETCH NEXT
FROM @f1 INTO @a
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @a
FETCH NEXT
FROM @f1 INTO @a
END
CLOSE @f1
Print 'Descending '
SET @f2 = CURSOR FOR
SELECT f1
FROM f_order order by 1 desc
OPEN @f2
FETCH NEXT
FROM @f2 INTO @b
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @b
FETCH NEXT
FROM @f2 INTO @b
END
CLOSE @f2
DEALLOCATE @f1
DEALLOCATE @f2
| Is This Answer Correct ? | 5 Yes | 2 No |
Post New Answer View All Answers
What view means?
Can instead of triggers be used to fire once for each statement on a view?
What are the types of records?
what is heap table? : Sql dba
What is sql profiling in oracle?
The select into statement is most often used to create backup copies of tables or for archiving records?
What is count * in sql?
Define union, minus, union all, intersect ?
how to check myisam tables for errors? : Sql dba
how to get @@error and @@rowcount at the same time? : Sql dba
How can we avoid duplicating records in a query?
What is microsoft t sql?
what are date and time intervals? : Sql dba
What are the query optimization techniques?
how to use myisamchk to check or repair myisam tables? : Sql dba