In one table there is 10 records without id num, without primary key and it is not sorted then how to extract last 6 record from table?
Submitted by: AdministratorCREATE TABLE Sample
(
Col1 varchar(5)
)
insert into Sample values('j')
TABLE:
Col1
j
r
c
r
e
f
g
h
x
j
USING CURSOR: ANSWER
DECLARE @COL1 VARCHAR(5)
DECLARE @COUNT VARCHAR(5)
SET @COUNT=0
DECLARE c1 CURSOR
FOR
SELECT COL1 FROM SAMPLE
OPEN C1
FETCH NEXT FROM C1
INTO @COL1
WHILE @@FETCH_STATUS=0
BEGIN
SET @COUNT=@COUNT+1
IF @COUNT>=5
BEGIN
SELECT @COL1
END
FETCH NEXT FROM C1
INTO @COL1
END
CLOSE C1
DEALLOCATE C1
Submitted by: Administrator
(
Col1 varchar(5)
)
insert into Sample values('j')
TABLE:
Col1
j
r
c
r
e
f
g
h
x
j
USING CURSOR: ANSWER
DECLARE @COL1 VARCHAR(5)
DECLARE @COUNT VARCHAR(5)
SET @COUNT=0
DECLARE c1 CURSOR
FOR
SELECT COL1 FROM SAMPLE
OPEN C1
FETCH NEXT FROM C1
INTO @COL1
WHILE @@FETCH_STATUS=0
BEGIN
SET @COUNT=@COUNT+1
IF @COUNT>=5
BEGIN
SELECT @COL1
END
FETCH NEXT FROM C1
INTO @COL1
END
CLOSE C1
DEALLOCATE C1
Submitted by: Administrator
Read Online SQL Server Errors Job Interview Questions And Answers
Top SQL Server Errors Questions
☺ | What is sqlcode -922 & -923? |
☺ | What will be the program output if it tries to access 11th item in an array of 10 and it is coded with NOSSRANGE? |
☺ | In one table there is 10 records without id num, without primary key and it is not sorted then how to extract last 6 record from table? |
☺ | How to solve "The SQL Server service failed to start. For more information, see the SQL Server Books Online topics" error? |
☺ | What is meant by write off and write on in sap? |
Top Exception Handling Categories
☺ | ERRORS Interview Questions. |
☺ | Scripts Errors Interview Questions. |
☺ | Oracle Errors Interview Questions. |
☺ | C C++ Errors Interview Questions. |
☺ | DotNet Errors Interview Questions. |