Solved

SQL Query Function Syntax Help

Posted on 2014-09-23
2
135 Views
Last Modified: 2014-09-23
Hello all,

Can someone give me an example how to do this.  

Select LocationName from CustomerLocation
Where CustId = 1

I am going to get multiple records I want to create a function that will give me back a comma string of Location Names as there could be 1 to Many records for a particular CustId.  Also need to strip the last comma.   So something like a varchar(500) I want to pass back with the return.

Thanks all
0
Comment
Question by:sbornstein2
2 Comments
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40339594
SELECT  STUFF(( SELECT ',' + LocationName
           
             from CustomerLocation
Where CustId = 1
              FOR
                XML PATH('')
              ), 1, 1, '') AS List
0
 

Author Closing Comment

by:sbornstein2
ID: 40339628
awesome thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now