Hi, i have a question, imagine that i have a table with names and phone numbers, like this:
Name | Phone
Jack | 2457349843
Jack | 9347842344
Mary | 4324324423
John | 3123123123
John | 43243244324
I want a query that returns something like this
Name | Phone
Jack | 2457349843, 9347842344
Mary | 4324324423
John | 3123123123, 43243244324
Thanks in advance, i really need this.
1 1534
Try this(Sql Server 2005+)
-- Table declarations with sample data - declare @t table(name varchar(50),phone bigint)
-
insert into @t
-
select 'Jack', 2457349843 union all select 'Jack', 9347842344 union all
-
select 'Mary', 4324324423 union all
-
select 'John', 3123123123 union all select 'John', 43243244324
--Program Starts - select name,LEFT(Phone,LEN(Phone) -1) as Phone from (
-
select t2.name,
-
(
-
select cast(phone as varchar(max)) + ','
-
from @t t1
-
where t1.name = t2.name
-
for XML path('')
-
) as Phone
-
from @t t2
-
group by t2.name)X(name,Phone)
Output
---------- name Phone - Jack 2457349843,9347842344
-
John 3123123123,43243244324
-
Mary 4324324423
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dan Gidman |
last post by:
Okay all I have a problem. I have two list of adresses and phone
numbers. I do not have control over the contents of the lists The only
unique field between the two is the phone number. I need...
|
by: Bruce Dodds |
last post by:
When run manually, my query appends 14 records. When run from code using
CurrentProject.Connection.Execute, the same query appends 11 records.
Does anyone have an explanation of why this could be...
|
by: nick.vitone |
last post by:
Hi,
I'm somewhat of a novice at Access, and I have no experience
programming whatsoever. I'm attempting to calculate the statistical
median in a query. I need to "Group by" one column and find...
|
by: Thomas A. Anderson |
last post by:
I have ran into a rut! I have google'd, Yahoo'd, but could not find the
proper syntax. I have spent over two day trying to figure this out, and
decided that I will have to ask for help from the...
|
by: Welie |
last post by:
I am trying to do a query to produce a list of employee and their
telephone numbers (IF ANY) which joins on 3 tables. The complication
is the 3rd table, the table containing telephone numbers....
|
by: rogynskyy |
last post by:
Hi guys,
I'm running MSDE 2000 A on Win XP
I've got a database with several tables, all of the tables display data in query manager.
I wrote this simple query:
Select
|
by: Phil Stanton |
last post by:
I am running a query that calls a function used to format addresses
depending on the width of a control on a report that shows that address. The
same query is used as the RecordSource of lots of...
|
by: lim4801 |
last post by:
I am currently in doing a program which is given by my tutor:
Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are...
|
by: deepu03 |
last post by:
Hi All
I have the following query to be tuned..
SELECT distinct a.EMPLID
,a.PER_ORG
,a.HIRE_DT
,a.grade
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |