Why oh why do I try to write code after 4pm on Fridays?
I've got a 3-column UserCustomerContact table:
userID customerID contactID
------ ---------- ---------
me 1 1
me 1 2
me 1 3
When I run this:
...I get a comma separated list of contactIDs: 1, 2, 3
So far so good.
When I run this:
...I get a comma separated list of customerIDs: 1, 1, 1
Not so good. What I really want is a list of DISTINCT customerIDs
This works for customerIDs (returns just the 1):
...but this returns just the last record for contactID:
Help?
< M!ke >
I've got a 3-column UserCustomerContact table:
userID customerID contactID
------ ---------- ---------
me 1 1
me 1 2
me 1 3
When I run this:
Code:
DECLARE @vcReturnValue varchar(100)
SELECT @vcReturnValue = COALESCE(@vcReturnValue + ', ', '')
+ CAST(contactID AS varchar(10))
FROM UserCustomerContact
WHERE UserID = 'me'
...I get a comma separated list of contactIDs: 1, 2, 3
So far so good.
When I run this:
Code:
DECLARE @vcReturnValue varchar(100)
SELECT @vcReturnValue = COALESCE(@vcReturnValue + ', ', '')
+ CAST(customerID AS varchar(10))
FROM UserCustomerContact
WHERE UserID = 'me'
...I get a comma separated list of customerIDs: 1, 1, 1
Not so good. What I really want is a list of DISTINCT customerIDs
This works for customerIDs (returns just the 1):
Code:
SELECT DISTINCT @vcReturnValue = COALESCE(@vcReturnValue + ', ', '')
+ CAST(customerID AS varchar(10))
FROM UserCustomerContact
WHERE UserID = 'me'
...but this returns just the last record for contactID:
Code:
SELECT DISTINCT @vcReturnValue = COALESCE(@vcReturnValue + ', ', '')
+ CAST(contactID AS varchar(10))
FROM UserCustomerContact
WHERE UserID = 'me'
Help?
< M!ke >