?
Solved

SQL Query Function Syntax Help

Posted on 2014-09-23
2
Medium Priority
?
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

770 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