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...


hi,
i have a table called names and field name
select * from names
name
a
b
c
d

i want to display like this
name
a,b,c,d
how it is possible


Regards
Baiju

Answers were Sorted based on User's Feedback



hi, i have a table called names and field name select * from names name a b c d i want to ..

Answer / soorai ganesh

Hi Friend,

If u use SQLSERVER 2005 u can try like this............

CREATE TABLE EMP ( ENAME VARCHAR(25))

INSERT INTO EMP VALUES('Ganesh')
INSERT INTO EMP VALUES('Narendra')
INSERT INTO EMP VALUES('Rinku')
INSERT INTO EMP VALUES('Selvam')
INSERT INTO EMP VALUES('Kirti')

SELECT REPLACE(REPLACE(
( SELECT ENAME AS EmpName FROM EMP FOR XML PATH ('') ) ,'<EmpName>',''),'</EmpName>',',')

Is This Answer Correct ?    6 Yes 0 No

hi, i have a table called names and field name select * from names name a b c d i want to ..

Answer / prasanna

create procedure loopcure
as
BEGIN
declare @a int, @b varchar(020), @l int, @c varchar(020),
@D varchar(020)
SET @D = ''
declare loopcur cursor for select id from names
open loopcur
fetch next from loopcur into @b
while @@fetch_status = 0
begin
select @C = LTRIM(RTRIM(@B)) + ','
select @D = LTRIM(RTRIM(@D)) + LTRIM(RTRIM(@C))
fetch next from loopcur into @b
end
close loopcur
deallocate loopcur
select @d = left(@d, len(@d)-1 )
select @d as final
END

Is This Answer Correct ?    3 Yes 0 No

hi, i have a table called names and field name select * from names name a b c d i want to ..

Answer / gopi muluka

CREATE TABLE Names (Name VARCHAR(50))
GO
INSERT Names
SELECT 'A'
UNION
SELECT 'B'
UNION
SELECT 'C'
UNION
SELECT 'D'
GO

-- FIRST METHOD
DECLARE @Name VARCHAR(50)
SELECT @Name=ISNULL(@Name,'')+ COALESCE(Name,',')+',' FROM
Names
SELECT LEFT(@Name,LEN(@Name)-1)
GO
--SECOND METHOD
DECLARE @chrString as varchar(200)
SET @chrString=''
SELECT @chrString=@chrString + ',' + Name FROM Names

SELECT SUBSTRING(@chrString,2, LEN(@chrString))

GO
DROP TABLE Names

Is This Answer Correct ?    1 Yes 0 No

hi, i have a table called names and field name select * from names name a b c d i want to ..

Answer / kulwinder

DECLARE @chrString as varchar(200)

select @chrString=@chrString + ',' + Name from Names

? @chrString

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More SQL Server Interview Questions

What is the purpose of linked server configuration in sql server?

0 Answers  


between cast and convert which function would you prefer and why?

0 Answers  


What is scan table/view and seek table/view when its occurs? : sql server database administration

0 Answers  


Create Index myIndex On myTable(myColumn) What type of Index will get created after executing the above statement

3 Answers  


How do I find the port number for sql server?

0 Answers  


how many triggers you can have on a table? : Sql server database administration

0 Answers  


what’s the difference between Covering Indexes and Clustered Indexes ? how to use clustered index small ?

0 Answers  


How is foreign key related to primary key?

0 Answers  


Explain filtered indexes?

0 Answers  


What is difference between process and thread? Explain lazy writer funcationality.

2 Answers   Microsoft,


What is the difference between system objects and user objects?

0 Answers   HCL,


You have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem?

0 Answers  


Categories