DECLARE @S VARCHAR(8000) SELECT @S='select salesmanname,isnull(so,''Wating for SO release'') as so,podname,services,FD,
BerthCanceltwentysize*0.5+BerthCancelfourtysize+BerthCancelhq+BerthCancelfortyfivesize as BerthCancelF,
twentysize*0.5+fourtysize+hq+fortyfivesize as ApplyF
from v_bk_BListProc ' + ltrim(@Sd)
+ ' and dbo.DateConvertWeek(si) between '+ ltrim(@Week1) + ' and '+ ltrim(@Week2)
EXEC(@S)
多个ltrim,多份正确保障.
BerthCanceltwentysize*0.5+BerthCancelfourtysize+BerthCancelhq+BerthCancelfortyfivesize as BerthCancelF,
twentysize*0.5+fourtysize+hq+fortyfivesize as ApplyF
from v_bk_BListProc ' + ltrim(@Sd)
+ ' and dbo.DateConvertWeek(si) between '+ ltrim(@Week1) + ' and '+ ltrim(@Week2)
EXEC(@S)
多个ltrim,多份正确保障.
SELECT @S='select salesmanname,isnull(so,''Wating for SO release'') as so,podname,services,FD,
BerthCanceltwentysize*0.5+BerthCancelfourtysize+BerthCancelhq+BerthCancelfortyfivesize as BerthCancelF,
twentysize*0.5+fourtysize+hq+fortyfivesize as ApplyF
from v_bk_BListProc ' + @Sd EXEC(@S)
BerthCanceltwentysize*0.5+BerthCancelfourtysize+BerthCancelhq+BerthCancelfortyfivesize as BerthCancelF,
twentysize*0.5+fourtysize+hq+fortyfivesize as ApplyF
from v_bk_BListProc ' + @Sd
+ ' and dbo.DateConvertWeek(si) between '+ CAST(@Week1 AS NVARCHAR(5)) + ' and '+ CAST(@Week2 AS NVARCHAR(5))
它是说 ' and dbo.DateConvertWeek(si) between ' 这个字符串转换成后面的类型-整形 出错
BerthCanceltwentysize*0.5+BerthCancelfourtysize+BerthCancelhq+BerthCancelfortyfivesize as BerthCancelF,
twentysize*0.5+fourtysize+hq+fortyfivesize as ApplyF
from v_bk_BListProc ' + @Sd
+ ' and dbo.DateConvertWeek(si) between '+ cast(@Week1 as varchar(10)) + ' and '+ cast(@Week2 as varchar(10))
EXEC(@S)
'' as coneefuname,'' as agentfuname,
vessel+''(Total)'' as vessel,'' as voyage,'' as por,'' as polname,
'' as etd,'' as stshname,
'' as comshname,sum(facttwentysize) as facttwentysize
,sum(factfourtysize) as factfourtysize,sum(facthq) as facthq,
sum(factfortyfivesize) as factfortyfivesize,'' as bkgaddshname
,'' as salesmanname,'' as so,'' as podname,'' as services,'' as FD,
sum(BerthCanceltwentysize)*0.5+sum(BerthCancelfourtysize)+sum(BerthCancelhq)+sum(BerthCancelfortyfivesize) as BerthCancelF,
sum(twentysize)*0.5+sum(fourtysize)+sum(hq)+sum(fortyfivesize) as ApplyF
from v_bk_BListProc ' + ltrim(@Sd)
+ ' and dbo.DateConvertWeek(si) between '+ ltrim(@Week1) + ' and '+ ltrim(@Week2)
+ ' group by vessel'提示:消息 102,级别 15,状态 1,第 3 行
'Total' 附近有语法错误。
消息 105,级别 15,状态 1,第 11 行
字符串 ' and dbo.DateConvertWeek(si) between 16 and 17 group by vessel' 后的引号不完整。
'''' as coneefuname,'''' as agentfuname,
vessel+''(Total)'' as vessel,'''' as voyage,'''' as por,'''' as polname,
'''' as etd,'''' as stshname,
'''' as comshname,sum(facttwentysize) as facttwentysize
,sum(factfourtysize) as factfourtysize,sum(facthq) as facthq,
sum(factfortyfivesize) as factfortyfivesize,'''' as bkgaddshname
,'''' as salesmanname,'''' as so,'''' as podname,'''' as services,'''' as FD,
sum(BerthCanceltwentysize)*0.5+sum(BerthCancelfourtysize)+sum(BerthCancelhq)+sum(BerthCancelfortyfivesize) as BerthCancelF,
sum(twentysize)*0.5+sum(fourtysize)+sum(hq)+sum(fortyfivesize) as ApplyF
from v_bk_BListProc ' + ltrim(@Sd)
+ ' and dbo.DateConvertWeek(si) between '+ ltrim(@Week1) + ' and '+ ltrim(@Week2)
+ ' group by vessel' 这样呢?