Solved

SQL Query Function Syntax Help

Posted on 2014-09-23
2
138 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 40

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

943 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

9 Experts available now in Live!

Get 1:1 Help Now