Linked Questions

2451 votes
51 answers
3.4m views

How to concatenate text from multiple rows into a single text string in SQL Server

Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into a single string of Peter, Paul, Mary?
JohnnyM's user avatar
  • 29.6k
0 votes
0 answers
46 views

TSQL: How do I join a subsequence result? [duplicate]

Let's say I have these tables: Table Persons: ID Name 1 John Table Groups: ID Group 1 Admin 2 Printer 3 Server Table PersonsAndGroups: ID person_ID group_ID 1 ...
MojoDK's user avatar
  • 4,568
63 votes
11 answers
212k views

How do I create a comma-separated list using a SQL query?

I have 3 tables called: Applications (id, name) Resources (id, name) ApplicationsResources (id, app_id, resource_id) I want to show on a GUI a table of all resource names. In one cell in each row I ...
leora's user avatar
  • 198k
76 votes
5 answers
102k views

Can I Comma Delimit Multiple Rows Into One Column? [duplicate]

I am attempting to merge something like this in my SQL Server database: [TicketID], [Person] T0001 Alice T0001 Bob T0002 Catherine T0002 Doug T0003 Elaine Into ...
John Gietzen's user avatar
  • 49.7k
85 votes
2 answers
100k views

Does T-SQL have an aggregate function to concatenate strings? [duplicate]

Possible Duplicates: Is there an Implode type function in SQL Server 2000? How can I group fields from multiple records in T-SQL by another field? I have a view which I'm querying that looks like this:...
Brant's user avatar
  • 15.4k
12 votes
3 answers
101k views

How to concat many rows into one string in SQL Server 2008? [duplicate]

How to concat many rows into one strings? Query: SELECT name FROM mytable; Result: name ---- kim lee park cho Just I want. name ---- kim,lee,park,cho Impossible?
chobo's user avatar
  • 4,892
6 votes
3 answers
11k views

How to pivot unknown number of columns & no aggregate in SQL Server?

I have query which returns clients loans with associated collateral names like below (1) but I want to have only one distinct loan number in a row and collateral names aside like on other example (2). ...
Zulu Z's user avatar
  • 1,141
4 votes
3 answers
17k views

Print bullet before each sentence + new line after each sentence SQL

I have a text like: Sentence one. Sentence two. Sentence three. I want it to be: Sentence one. Sentence two. Sentence three. I assume I can replace '.' with '.' + char(10) + char(13), but how can I ...
user194076's user avatar
  • 9,045
1 vote
1 answer
498 views

How to return an string with concatenate values into an field (SQL script)

This SQL Server stored procedure returns a string with values delimited by single commas and placing an apostrophe before each value. Uses a table named Sucursal and returns an string with all ...
César Qüeb's user avatar
4 votes
1 answer
92 views

Get SQL Server's constraints list without redundancy

With this query I get the list of all my database's CHECK, FOREIGN_KEY, PRIMARY_KEY and UNIQUE_KEY constraints. SELECT o.object_id as ID, o.name AS Name, OBJECT_NAME(o.parent_object_id) AS ...
J.P.A's user avatar
  • 105
0 votes
2 answers
106 views

SQL Server 2008R2 Custom Function so slow

Here is my function: -- DECLARE @cur CURSOR DECLARE @line int declare @return varchar(255) DECLARE myCursor CURSOR FOR SELECT DISTINCT (quote_ln_no) as quote_ln_no FROM dbo.quote_line_bom WHERE ...
user3456419's user avatar
0 votes
0 answers
133 views

Comma-separated values with SQL query [duplicate]

Possible Duplicate: Sql select group by and string concat My SQL table looks like this: City_Code Post_Code Post_Code_Description 100 A1 ABC 100 C8 ...
InTheWorldOfCodingApplications's user avatar
0 votes
1 answer
107 views

SQL How to add values of a select statement to a varchar

I'm writing a function that returns the names of a child table's one column's values in one varchar. The relation is: I have a parent table called Activity. And a child table in N-1 relation with ...
Zafer Sernikli's user avatar
0 votes
2 answers
64 views

MySQL: How to join three tables in one query with an assign table?

I have three tables: ITEMS itemid | itemname 1 | Item 1 FEATURES featureid | featurename 1 | feature1 2 | feature2 3 | feature3 4 | feature4 ... | ... ...
rockstardev's user avatar
  • 13.6k
0 votes
2 answers
58 views

Need Oracle Query to Retrieve info from tables with 1 to Many Relationship

I have tables with information similar to the following: Table A is a list of circuits: Circuit | CktType | CktSize -------------------------------- CKT1 | ABC123 | 10 CKT2 | ABC123 ...
David McCarthy's user avatar

15 30 50 per page