i have a table student like
sname
-----
ram
ram
ram
raj
raj
raj
i need the output like
sname
-----
ram
raj
ram
raj
ram
raj

Answer Posted / shunmuga priya

--The query to work in SQL server 2000
declare @cnt int
select @cnt = count(sname) from student where sname ='ram'

declare @student table
(sname varchar(20))

while @cnt <> 0
begin
insert @student
select * from student where sname like 'raj'
union
select * from student where sname like 'ram'
order by sname desc
set @cnt = @cnt - 1
End

select * from @student

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the template in sql?

728


What is trigger explain with program?

708


What command is used to delete a table from the database in the sql server and how?

741


What are the security related catalog views? : sql server security

703


What is normalization of database? What are its benefits?

680






Explain the creation and execution of a user-defined function in the sql server?

781


Explain user defined views?

744


Do you know how to store and query spatial data?

780


What is the use of keyword with encryption.

783


How to encrypt data between dialogs?

764


What is dknf in normalization form?

731


What does select 1 mean?

729


What are the aggregate and scalar functions?

704


When should you use an instead of trigger?

701


How you would rewrite the sql query to return the customerid sorted numerically?

755