473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

column values concatenation

hi all , actually i am binding a datagrid with a dataview which has a
datatable showing output like
this..
propertyid viewname
1 fronside
1 lefttside
1 rightside..
2 frontside
2 leftside
3 rightside
3 leftside

i need the output like that..
propertyid viewname
1 fronside,leftside,rightside
2 fronside,leftside
3 leftside,rightside

------------
what can i do to concatenate column values??
Oct 20 '08 #1
1 1821
"CreativeMind" <af*********@gmail.comwrote in message
news:68**********************************@t18g2000 prt.googlegroups.com...
hi all , actually i am binding a datagrid with a dataview which has a
datatable showing output like
this..
propertyid viewname
1 fronside
1 lefttside
1 rightside..
2 frontside
2 leftside
3 rightside
3 leftside

i need the output like that..
propertyid viewname
1 fronside,leftside,rightside
2 fronside,leftside
3 leftside,rightside

------------
what can i do to concatenate column values??
One approach might be to make this an SQL problem, by writing a stored
procedure that creates a temporary table and concatenates the data.

-- create a temporary table to hold the results
CREATE TABLE #temp(propertyid INT, viewname VARCHAR(100))

-- copy unique property id values to temporary table
INSERT #temp SELECT DISTINCT propertyid, '' FROM myTable

-- set up a cursor to iterate through the source table
DECLARE @id INT, @name VARCHAR(50)
DECLARE c CURSOR FOR SELECT propertyid, viewname FROM myTable
OPEN c

-- get the first record
FETCH NEXT FROM c INTO @id, @name

WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE #temp SET viewName=viewName +' ' + @name where propertyid = @id
FETCH NEXT FROM c INTO @id, @name
END

-- get the final results, trimming extra space from start
SELECT propertyid, LTRIM(viewname) as viewname FROM #temp

--
Robert Dunlop
----------------------
http://www.directxzone.org
http://rdunlop.spaces.live.com
Microsoft DirectX MVP 1998-2006
Oct 21 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: david.buckingham | last post by:
I have a customer who has recently migrated their SQL server to a new server. In doing so, a portion of a stored procedure has stopped working. The code snippet is below: declare @Prefixes...
3
by: graphicsxp | last post by:
Hi, I have a SQL stored procedure which looks like that: SELECT @QuerySQL = 'SELECT as LookupField, G.GroupDesc + ' + '" : "' + ' + as DescField FROM ' + 'JOIN ItemGrouping IG on IG.CatID...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
2
by: John | last post by:
Hi I have an email column in a table. How can I turn values in the column for all records into a single string with each email separated by a ;? Thanks Regards
12
by: parth | last post by:
Hi I want to achieve the following transformation of data using a stored procedure. Source col1 col2(varchar) -------------------------
6
by: NarutoFanatic | last post by:
Hi! I need help in MS ACCESS, I need to create a query that could move different rows into another column. More like concatenation but in a different column rather than in one column. Example: ...
6
by: candide_sh | last post by:
Hello, can I do this via SQL: example: tbltest has 5 rows: col1 === A C
4
by: Chronictank | last post by:
Hi, as a bit of background (and seeing as it is my first post :)) i am a complete newbie at perl. I literally picked it up a week ago to do this project as it seemed like the best choice for a...
1
by: virax | last post by:
Hello all, I'm working on a solution that interfaces with a PostgreSQL db, which occasionally uses the || operator to concatenate column values in a SELECT statement. Visual Studio 2005 is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.