473,382 Members | 1,736 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,382 software developers and data experts.

Combining Values

I need to do something that goes against normalization, but it is what
the client wants. Let's say one person has several addresses. I need
to be able to take each of those addresses and combine them into one
field. So I need to take this:

John Doe | Address 1
John Doe | Address 2
John Doe | Address 3

And combine them into this:

John Doe | Address 1; Address 2; Address 3
Do I need a cursor for this?

Jun 29 '07 #1
7 1941
im*******************@yahoo.com wrote:
I need to do something that goes against normalization, but it is what
the client wants. Let's say one person has several addresses. I need
to be able to take each of those addresses and combine them into one
field. So I need to take this:

John Doe | Address 1
John Doe | Address 2
John Doe | Address 3

And combine them into this:

John Doe | Address 1; Address 2; Address 3
Do I need a cursor for this?
Do this in the reporting layer (e.g. Crystal Reports) if at
all possible.
Jun 30 '07 #2
I wish I could, but this is a data migration. I HAVE to put this
stuff in the table. The customer requires it. More specifically,
Commerce Server requires it.

On Jun 29, 6:55 pm, Ed Murphy <emurph...@socal.rr.comwrote:
imani_technology_s...@yahoo.com wrote:
I need to do something that goes against normalization, but it is what
the client wants. Let's say one person has several addresses. I need
to be able to take each of those addresses and combine them into one
field. So I need to take this:
John Doe | Address 1
John Doe | Address 2
John Doe | Address 3
And combine them into this:
John Doe | Address 1; Address 2; Address 3
Do I need a cursor for this?

Do this in the reporting layer (e.g. Crystal Reports) if at
all possible.- Hide quoted text -

- Show quoted text -

Jun 30 '07 #3

If you cant do this in reports, refer this

http://sqljunkies.com/WebLog/amachan...x?Pending=true

Madhivanan
On Jun 30, 10:47 am, "imani_technology_s...@yahoo.com"
<imani_technology_s...@yahoo.comwrote:
I wish I could, but this is a data migration. I HAVE to put this
stuff in the table. The customer requires it. More specifically,
Commerce Server requires it.

On Jun 29, 6:55 pm, Ed Murphy <emurph...@socal.rr.comwrote:
imani_technology_s...@yahoo.com wrote:
I need to do something that goes against normalization, but it is what
the client wants. Let's say one person has several addresses. I need
to be able to take each of those addresses and combine them into one
field. So I need to take this:
John Doe | Address 1
John Doe | Address 2
John Doe | Address 3
And combine them into this:
John Doe | Address 1; Address 2; Address 3
Do I need a cursor for this?
Do this in the reporting layer (e.g. Crystal Reports) if at
all possible.- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Jun 30 '07 #4
im*******************@yahoo.com wrote:
I wish I could, but this is a data migration. I HAVE to put this
stuff in the table. The customer requires it. More specifically,
Commerce Server requires it.
You have three options:

1) aggregate concatenation in cursor
2) aggregate concatenation in SELECT query
3) aggregate concatenation using FOR XML

Option 1) is the safest method.

For option 2) details refer to:
http://groups.google.pl/group/micros...ab9fecb969f34/

Third method:
http://sqlblogcasts.com/blogs/tonyro...07/06/871.aspx
--
Best regards,
Marcin Guzowski
http://guzowski.info
Jun 30 '07 #5
Here's where things get interesting:

John Doe | Address 1
John Doe | Address 2
John Doe | Address 3
Jane Smith | Address 1
Jane Smith | Address 2

The results need to be

John Doe | 3; Address 1; Address 2; Address 3
Jane Smith | 2; Address 1; Address 2

I have no idea how to pull this off.

On Jun 30, 6:39 am, "Marcin A. Guzowski"
<tu_wstaw_moje_i...@guzowski.infowrote:
imani_technology_s...@yahoo.com wrote:
I wish I could, but this is a data migration. I HAVE to put this
stuff in the table. The customer requires it. More specifically,
Commerce Server requires it.

You have three options:

1) aggregate concatenation in cursor
2) aggregate concatenation in SELECT query
3) aggregate concatenation using FOR XML

Option 1) is the safest method.

For option 2) details refer to:http://groups.google.pl/group/micros...r.programming/...

Third method:http://sqlblogcasts.com/blogs/tonyro...07/06/871.aspx

--
Best regards,
Marcin Guzowskihttp://guzowski.info

Jul 1 '07 #6
On Jul 2, 12:48 am, "imani_technology_s...@yahoo.com"
<imani_technology_s...@yahoo.comwrote:
Here's where things get interesting:

John Doe | Address 1
John Doe | Address 2
John Doe | Address 3
Jane Smith | Address 1
Jane Smith | Address 2

The results need to be

John Doe | 3; Address 1; Address 2; Address 3
Jane Smith | 2; Address 1; Address 2

I have no idea how to pull this off.

On Jun 30, 6:39 am, "Marcin A. Guzowski"

<tu_wstaw_moje_i...@guzowski.infowrote:
imani_technology_s...@yahoo.com wrote:
I wish I could, but this is a data migration. I HAVE to put this
stuff in the table. The customer requires it. More specifically,
Commerce Server requires it.
You have three options:
1) aggregate concatenation in cursor
2) aggregate concatenation in SELECT query
3) aggregate concatenation using FOR XML
Option 1) is the safest method.
For option 2) details refer to:http://groups.google.pl/group/micros...r.programming/...
Third method:http://sqlblogcasts.com/blogs/tonyro...07/06/871.aspx
--
Best regards,
Marcin Guzowskihttp://guzowski.info- Hide quoted text -

- Show quoted text -
You could use a WHILE loop to select row by row for each person.
SELECT the COUNT of addresses for the current person into one variable
and build up a text string of the concatenated addresses into another
variable looping round until you've got them all. Then update the
column in the table with the value of the variables.

Jul 2 '07 #7
Sorry, I'm a little rusty on cursors. How would I pull this off? Can
I (or should I) use nested WHILE loops?

On Jul 2, 3:28 am, Stephen2 <Step...@mailinator.comwrote:
On Jul 2, 12:48 am, "imani_technology_s...@yahoo.com"

<imani_technology_s...@yahoo.comwrote:
Here's where things get interesting:
John Doe | Address 1
John Doe | Address 2
John Doe | Address 3
Jane Smith | Address 1
Jane Smith | Address 2
The results need to be
John Doe | 3; Address 1; Address 2; Address 3
Jane Smith | 2; Address 1; Address 2
I have no idea how to pull this off.
On Jun 30, 6:39 am, "Marcin A. Guzowski"
<tu_wstaw_moje_i...@guzowski.infowrote:
imani_technology_s...@yahoo.com wrote:
I wish I could, but this is a data migration. I HAVE to put this
stuff in the table. The customer requires it. More specifically,
Commerce Server requires it.
You have three options:
1) aggregate concatenation in cursor
2) aggregate concatenation in SELECT query
3) aggregate concatenation using FOR XML
Option 1) is the safest method.
For option 2) details refer to:http://groups.google.pl/group/micros...r.programming/...
Third method:http://sqlblogcasts.com/blogs/tonyro...07/06/871.aspx
--
Best regards,
Marcin Guzowskihttp://guzowski.info-Hide quoted text -
- Show quoted text -

You could use a WHILE loop to select row by row for each person.
SELECT the COUNT of addresses for the current person into one variable
and build up a text string of the concatenated addresses into another
variable looping round until you've got them all. Then update the
column in the table with the value of the variables.- Hide quoted text -

- Show quoted text -

Jul 2 '07 #8

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

Similar topics

2
by: perplexed | last post by:
Is there a way to combine the values of multiple form items such as two textboxes and one radio button for insertion into one MYSQL database field?
4
by: John | last post by:
I currently have a list box that contains regions in the US (Northeast, Midwest, South, etc.). I am retrieving this data from my Region table(see below). Users have the ability to select a region...
5
by: JackT | last post by:
Hi, I have the following SQL SELECT Table1.Col1, Table3.Col1 AS Expr1, COUNT(Table1.Col2) AS Col2_No, COUNT(Table1.Col3) AS Col3_No etc, FROM Table3 INNER JOIN Table2 ON...
5
by: Steve | last post by:
I have a table; CREATE TABLE theLiterals ( theKey varchar (255) NOT NULL , theValue varchar (255) NULL ) INSERT INTO theLiterals VALUES('defaultServer','\\MyServer\') INSERT INTO...
8
by: mikea_59 | last post by:
I am having trouble combining similar elements. Elements can be combined if they have the same name and the same attribute values. I can handle single level elements but am having problems with...
2
by: Chris Mullins | last post by:
I've spent a bit of time over the last year trying to implement RFC 3454 (Preparation of Internationalized Strings, aka 'StringPrep'). This RFC is also a dependency for RFC 3491...
2
by: rpeacock | last post by:
I have a function that takes a field with values separated by commas within the field and splits them to multiple rows. Example: Field - Interior Value - abc,def,efg,ghi Output: ID Item 1 ...
1
by: Ken Fine | last post by:
I am wondering if there is a build-in method in .NET for arbitrarily and correctly combining/concatenating querystring variables into a valid querystring. i.e. I might have the following vars I...
1
by: dlee360 | last post by:
Hello! So I've been trying to figure out how to do the following in T-SQL: Orig Table: Col1 Col2 Col3 Set A ...
4
bilibytes
by: bilibytes | last post by:
Hi, i am trying to INSERT into a table lets say 4 values: - value1 - value2 - value3 - value4 all these values are stored in variables($var1, $var2, $var3..), except one of them which is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.