Hi,
I did that:
Select * from OppSalesTeam where role = 'Financing' and Opportunity = '123456';
The result is this:
ID role name Opportunity
2143 Financing bank 123456
4141 Financing owner 123456
But, I would that the result seem like that:
ID role name Opportunity
2143 Financing bank ; owner 123456
I just want 1 row that contains the names for this Opportunity, but I don't know how I can do that.
I tried this code...
CREATE FUNCTION dbo.ConcatSourceOfFinancing ( @Opportunity_ID varchar(32) )
RETURNS varchar(400) AS
BEGIN
DECLARE @value varchar(400)
SET @value = ''
SELECT @value = @value + Org.OrgName + ' ; '
FROM OppSalesTeam OST inner join org on (ost.org_id = org.org_id)
WHERE role = 'Financing' and OST.Opportunity_ID = @Opportunity_ID
ORDER BY Org.OrgName
if @value <> ''
set @value = left(@value, len(@value) - 2)
Return @value
END -- Function
It works well, but if I have over 1000 records, it fails. Maybe because call this function over 1000 times, the server don`t like that.
What can I do with this function to be faster and more robust???
Thank you
I did that:
Select * from OppSalesTeam where role = 'Financing' and Opportunity = '123456';
The result is this:
ID role name Opportunity
2143 Financing bank 123456
4141 Financing owner 123456
But, I would that the result seem like that:
ID role name Opportunity
2143 Financing bank ; owner 123456
I just want 1 row that contains the names for this Opportunity, but I don't know how I can do that.
I tried this code...
CREATE FUNCTION dbo.ConcatSourceOfFinancing ( @Opportunity_ID varchar(32) )
RETURNS varchar(400) AS
BEGIN
DECLARE @value varchar(400)
SET @value = ''
SELECT @value = @value + Org.OrgName + ' ; '
FROM OppSalesTeam OST inner join org on (ost.org_id = org.org_id)
WHERE role = 'Financing' and OST.Opportunity_ID = @Opportunity_ID
ORDER BY Org.OrgName
if @value <> ''
set @value = left(@value, len(@value) - 2)
Return @value
END -- Function
It works well, but if I have over 1000 records, it fails. Maybe because call this function over 1000 times, the server don`t like that.
What can I do with this function to be faster and more robust???
Thank you