Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Putting several rows of one field into a variable?

Author  Topic 

mdProgrammer
Starting Member

3 Posts

Posted - 2005-11-04 : 16:36:59
I'm not quite sure how to tackle this (a few attempts didn't work), but let's say I have a table that lists 2 columns (for example, city and name). Now, the city field does repeat, and will have several different names. Here's an example:

Atlanta		Joe
Atlanta Sue
Atlanta Fred
Baltimore Jim
Baltimore Kelly
Baltimore Amy
Cincinatti Pete
Cincinatti Bill
Cincinatti Sarah


What I want it to do is to put all names from 1 city into 1 variable (so that I can put it into a larger query). So, it might be something like this:

City 		Name
Atlanta Joe
Sue
Fred

Baltimore Jim
Kelly
Amy

Cincinatti Pete
Bill
Sarah


The final result would look something like this:

Table with 2 records:
SomeField1 SomeField2 SomeField3 Names
XYZ XYZ XYZ Pete
Bill
Sarah
------------------------------------------------------
XYZ XYZ XYZ Jim
Kelly
Amy
------------------------------------------------------


So, how would I do this?

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2005-11-04 : 17:07:53
If you are talking about suppressing duplicate data on consecutive rows, this is a common feature of reporting software such as Crystal or MS Access. It is a formatting issue, and should be handled by your presentation layer. QUERY ANALYZER IS NOT A USER INTERFACE!

Can this be done using SQL code? Yes. But it is purely an exercise in MaSQLbation, so don't do it.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-11-04 : 17:17:04
>>But it is purely an exercise in MaSQLbation, so don't do it.

Wait a minute, your name is BlindMan? You mean what my mother told me is true?!?

Be One with the Optimizer
TG
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2005-11-04 : 19:10:35
Not sure what your mother told you, but most of what my mother told me turned out to be true...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-05 : 00:28:45
Where do you want to show these data?
If you are using Reports, then use its "Suppress If Duplicated" feature

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

t1g312
Posting Yak Master

148 Posts

Posted - 2005-11-05 : 03:25:45
quote:
Originally posted by TG

>>But it is purely an exercise in MaSQLbation, so don't do it.

Wait a minute, your name is BlindMan? You mean what my mother told me is true?!?

Be One with the Optimizer
TG



Blindman, do you have pimples on your face as well? :P

Adi
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2005-11-05 : 22:05:12
I'm much too old for that. But it sure is a pain shaving my palms every week.
Go to Top of Page

mdProgrammer
Starting Member

3 Posts

Posted - 2005-11-07 : 09:16:58
Umm, guys? I'm trying get help here, not read spam.

I have a dyanmic datagrid in ASP.NET that uses a query to get some data, but... in one new column, I want it to list some data based on a value in that row. (similar to a nested datagrid I guess). The data I want is shown in several rows. What I want to do is to combine them onto a single line - (like "data1, data2, data3").
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-07 : 09:23:15
Do you need something like this?
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Otherwise show us some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mdProgrammer
Starting Member

3 Posts

Posted - 2005-11-07 : 09:54:59
That's exactly what I was looking for. Thanks.

I had some code close to it, but just couldn't figure out the correct way of going about it.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-07 : 10:42:51
quote:
Originally posted by mdProgrammer

Umm, guys? I'm trying get help here, not read spam.



Oh, relax....That's not spam....and if you want help read the link below in my sig....you r original post wasn't very clear...

Also, read this, cause I'm still not clear...

http://weblogs.sqlteam.com/brettk/archive/2005/10/10/7987.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -