Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

there is a table having two columns no and name
and the data is
1 A
2 B
3 C

write a query that will result a horizontal output
A,B,C

Answer Posted / kumar.t

1. First To create the following table.

Create table NewNew(sno int identity(1,1) primary key,
names varchar(100))

2. To INsert the record one by one

Insert Into NewNew Values ('A')
Insert Into NewNew Values ('B')
Insert Into NewNew Values ('C')
Insert Into NewNew Values ('D')
Insert Into NewNew Values ('F')

3. To view the records first

Select * From NEwNew

4. To create the following procedure

Create Proc New1
As
Begin
Declare @names varchar(100)
Declare @sQuery Varchar(7000)
Declare @sQuery1 Varchar(1000)
Declare @ans varchar(8000)
Declare @i int
Declare cur cursor for select names from newnew
Open cur
Set @i = 1
Set @sQuery1 = ''
Set @sQuery = ''
fetch next from cur into @names
While @@fetch_status=0
Begin
Set @sQuery1 = '(Select Top 1 names
from newnew where names in (select top '+ convert(varchar
(3),@i) +' names From newnew order by 1 Asc) order by 1
Desc) As names,'
Set @sQuery = @squery + @squery1
Set @i = @i + 1
Fetch next from cur into @names
End
Set @ans = Convert(varchar(6),'Select ') +
Left(@sQuery,Len(@sQuery)-1)
Exec (@ans)
Close cur
deallocate cur
End

5. To execute the procedure
now to view the output Ok

Exec New1


By
Kumar.T

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain datetimeoffset data type in sal server 2008?

852


OPTIMIZATION OF SP,CURSOR,TRIGGERS

2707


What is database replication? What are the different types of replication you can set up in sql server?

913


How to send email from database?

953


How to download and install sql server 2005 books online?

1087


Can you change the data type of a column in a table after the table has been created? If so, which command would you use?

978


Help!!!!!!!!!!!! My database has gone offline, it is highlighted as 'Suspect'. Foolishly, i haven't got a recent back up. Is there a way of quickly restoring the database? Thank you

1706


Tell me what is de-normalization and what are some of the examples of it?

958


Give some Scenario for Non Clusterd index? Can we write system defined functions in side The Function? Wat is the Unique Datatype?

2448


What are drilldown reports?

140


What is a trigger and its types?

929


What is a db view?

856


What is the use of toad or sqldbx.?

1102


How to send a ssrs report from ssis?

166


State the difference between union and union all?

889