Hello All. I have a Read-Only VB.NET data grid in which I want to show an employee roster with email addresses and phone numbers from an SQL 2000 database. The data needs to look like the following in the data grid:
To do this I am trying to use the sql coalesce statement to prepare a delimited string in which I will use carriage returns in the data grid to bump the multiple email addresses and phone numbers down a line within each cell. The following code returns a comma delimited string in which I can replace the commas with carriage returns.
This works well and returns "Bill.Clinton@here.com, Bill@yahoo.com" as needed.
The question is, can this be done from within a sub Select? Or is there a better way to get the data in the format that I wanting?
The stored proc that I have so far is:
This returns an error: "
"
Any ideas or advice would be much appreciated.
Rich
Code:
Employee Email Phone
Clinton, Bill Bill.Clinton@here.com Cell: (502) 111-2222
Bill@yahoo.com Desk: (502) 111-1234
Bush, George pres@whitehouse.gov Cell: (504) 441-2789
dubya@yahoo.com Desk: (502) 111-9514
Page: (445) 789-2442
Public, John Q jpublic@yahoo.com Desk: (502) 111-2587
... Others ....
To do this I am trying to use the sql coalesce statement to prepare a delimited string in which I will use carriage returns in the data grid to bump the multiple email addresses and phone numbers down a line within each cell. The following code returns a comma delimited string in which I can replace the commas with carriage returns.
Code:
DECLARE @Email varchar(100)
SELECT @Email = COALESCE(@Email + ', ', '') +
CAST(EmailAddress AS varchar(50))
FROM EmployeeEmail
WHERE EmployeeID = 8
SELECT @Email
This works well and returns "Bill.Clinton@here.com, Bill@yahoo.com" as needed.
The question is, can this be done from within a sub Select? Or is there a better way to get the data in the format that I wanting?
The stored proc that I have so far is:
Code:
ALTER PROCEDURE SP_Roster_SelectList_test
AS
DECLARE @EmailAddress varchar(1000)
SELECT
e.EmployeeID ,
e.LastName ,
e.FirstName ,
EmailAddress =
(Select @EmailAddress = COALESCE(em.EmailAddress + ', ', '') +
CAST(em.EmailAddress AS varchar(50))
FROM EmployeeEmail em
WHERE em.EmployeeID = e.EmployeeID
Select @EmailAddress
),
FROM Employees e
ORDER BY e.LastName, e.FirstName
Code:
Line 11: Incorrect syntax near '='.
Any ideas or advice would be much appreciated.
Rich