select ci.*,gei.company_code,gei.examine_id,gei.risk_judge,ttc5.work_shop_name,ttc6.over_work_shop_name
from company_info ci
left join gs_examine_info gei on ci.company_code=gei.company_code and gei.project_id='2'
left join (select gwi.examine_id,dbo.Concatenate(distinct gwi.work_shop_name+',') as work_shop_name
from gs_workspace_info gwi
GROUP BY gwi.examine_id
) ttc5 on ttc5.examine_id=gei.examine_id
left join ( select gwi3.examine_id,dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ghi.over_number+',') as over_work_shop_name
from gs_workspace_info gwi3
inner join gs_harm_info ghi on gwi3.workspace_id=ghi.workspace_id
inner join profession_harm_base_data phbd on phbd.harm_code=ghi.profession_harm_code
group by gwi3.examine_id
) ttc6 on ttc6.examine_id=gei.examine_id
where (( ci.position_district_id = 4 ) and ( ci.status = 1 or ci.status = 2 ) and ( ci.status = 1 or ci.status = 2 ))
order by ci.company_id
using System;
using System.Data.SqlTypes;
using System.IO;
using System.Text;
using Microsoft.SqlServer.Server;
[Serializable]
[SqlUserDefinedAggregate(Format.UserDefined, IsInvariantToNulls = true, IsInvariantToDuplicates = false, IsInvariantToOrder = false, MaxByteSize = 8000, Name = "Concatenate")]
public class Concatenate : IBinarySerialize
{
private StringBuilder _intermediateResult;
internal string IntermediateResult {
get
{
return _intermediateResult.ToString();
}
}
public void Init()
{
_intermediateResult = new StringBuilder();
}
public void Accumulate(SqlString value)
{
if (value.IsNull) return;
_intermediateResult.Append(value.Value);
}
public void Merge(Concatenate other)
{
if (null == other)
return;
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ghi.over_number+',') as over_work_shop_name
应该是这句,改成这样的
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ltrim(ghi.over_number)+',') as over_work_shop_name
#4
不对啊,报错是float转varchar错误啊,感觉可能是函数定义错了
CREATE AGGREGATE [dbo].[Concatenate] (@value [nvarchar](max))
RETURNS [nvarchar](max)
EXTERNAL NAME [concat].[Concatenate]
GO
returns 是nvarchar类型 ,应该怎么改好呢
#5
我一开始表述错了 是float转varchar错误
#6
好吧 被绕晕了 确实是varchar转float错误啊 float转varchar也不会报错啊
#7
按 3# 的建议修改了吗?
#8
改了的 没用
#9
把涉及到的到表结果都说一下,估计还有别的字段是数值型;
#10
好吧 被绕晕了 确实是varchar转float错误啊 float转varchar也不会报错啊
按 3# 的建议修改了吗?
改了的 没用
改了以后是这样的结果,有些数据丢失了
#11
好了 解决了
#12
select gwi3.examine_id,dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+isnull(ltrim(ghi.over_number),0)+',') as merge_str
from gs_workspace_info gwi3
inner join gs_harm_info ghi on gwi3.workspace_id=ghi.workspace_id
inner join profession_harm_base_data phbd on phbd.harm_code=ghi.profession_harm_code
group by gwi3.examine_id
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ghi.over_number+',') as over_work_shop_name
应该是这句,改成这样的
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ltrim(ghi.over_number)+',') as over_work_shop_name
#4
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ghi.over_number+',') as over_work_shop_name
应该是这句,改成这样的
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ltrim(ghi.over_number)+',') as over_work_shop_name
不对啊,报错是float转varchar错误啊,感觉可能是函数定义错了
CREATE AGGREGATE [dbo].[Concatenate] (@value [nvarchar](max))
RETURNS [nvarchar](max)
EXTERNAL NAME [concat].[Concatenate]
GO
returns 是nvarchar类型 ,应该怎么改好呢
#5
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ghi.over_number+',') as over_work_shop_name
应该是这句,改成这样的
dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+ltrim(ghi.over_number)+',') as over_work_shop_name
我一开始表述错了 是float转varchar错误
#6
好吧 被绕晕了 确实是varchar转float错误啊 float转varchar也不会报错啊
#7
好吧 被绕晕了 确实是varchar转float错误啊 float转varchar也不会报错啊
按 3# 的建议修改了吗?
#8
好吧 被绕晕了 确实是varchar转float错误啊 float转varchar也不会报错啊
按 3# 的建议修改了吗?
改了的 没用
#9
把涉及到的到表结果都说一下,估计还有别的字段是数值型;
#10
好吧 被绕晕了 确实是varchar转float错误啊 float转varchar也不会报错啊
按 3# 的建议修改了吗?
改了的 没用
改了以后是这样的结果,有些数据丢失了
#11
好了 解决了
#12
select gwi3.examine_id,dbo.Concatenate(distinct work_shop_name+'|'+harm_name+'|'+isnull(ltrim(ghi.over_number),0)+',') as merge_str
from gs_workspace_info gwi3
inner join gs_harm_info ghi on gwi3.workspace_id=ghi.workspace_id
inner join profession_harm_base_data phbd on phbd.harm_code=ghi.profession_harm_code
group by gwi3.examine_id