我将Crystal的报告导入SSRS。
当我在Microsoft管理控制台中运行查询时,除非我在SELECT语句之前声明变量,否则它会抛出错误。当我从Visual Studio运行查询时,它会绕过这些变量并仅在TRIM函数上抛出错误。
据我所知,可以使用JOIN语句代替TRIM,但我不确定。
这是我试图改变/适应SSRS的where子句的一部分,这是一个错误 - 任何建议都值得赞赏。
另外,我在WHERE子句中遇到DateSerial问题如下:
AND(CAST(@StartDate AS Date)<> DateSerial(1900,01,01))AND
答案 0 :(得分:0)
Trim在SQL中不起作用,只能在报表表达式中使用LTrim和RTrim才能使其工作。
AND ( ( NOT ( @Status IS NULL )
AND RTrim(LTrim(@Status)) <> 'All' )
(( ( RTrim(Ltrim(@Status)) = 'Completed' )
AND RTrim(LTrim(@AssignedTo)) <> 'All' )
AND ( submission.assignedto IN ( @AssignedTo ) )
包括完整的条款:
WHERE ( @ParameterIds IS NOT NULL or ParameterIds = @ParameterIds )
AND @ParameterIds <> 0 )
AND ( requested_table.parameterid IN ( @ParameterIds ) ) )
AND requested_table.columnname = 'INSERT'
AND ( ( NOT ( @Parameter2 IS NULL )
AND Trim(@Parameter2) <> 'All' )
AND (( ( Trim(@Parameter2) = 'Completed' )
AND (( requested_table.columnname = 'Dup'
OR requested_table.columnname = 'IDup'
OR requested_table.columnname = 'W/D'
OR requested_table.columnname = 'Done'
OR requested_table.columnname = 'QA Review Dup'
OR requested_table.columnname = 'X' ))
OR ( requested_table.columnname IN ( @Parameter2 ) ) )) )
AND ( ( @ParameterIds = 0 )
AND ( ( ( NOT ( @StartDate IS NULL )
AND ( Cast (@StartDate AS DATE) <>
Dateserial(1900, 01, 01) ) )
AND ( submission.dateimported >= Datevalue (@StartDate) ) )
AND ( ( NOT ( @EndDate IS NULL )
AND ( Cast (@EndDate AS DATE) <>
Dateserial(1900, 01, 01) )
)
AND ( table.dateimported <= Datevalue (@EndDate) )
) ) )
AND ( ( @ParameterIds = 0 )
AND (( ( NOT ( @Parameter5 IS NULL )
AND Trim(@Parameter5) <> 'All' )
AND ( table.assignedto IN ( @Parameter5 ) ) )) )
修复Dateserial,这应该有效。
WHERE ( @ParameterIds IS NOT NULL or ParameterIds = @ParameterIds )
AND (@ParameterIds <> 0 )
AND ( requested_table.parameterid IN ( @ParameterIds ) )
AND requested_table.columnname = 'INSERT'
AND ( ( (@Parameter2 IS NOT NULL )
AND LTRIM(RTrim(@Parameter2)) <> 'All' )
AND (( ( LTRIM(RTrim((@Parameter2)) = 'Completed' )
AND (( requested_table.columnname = 'Dup'
OR requested_table.columnname = 'IDup'
OR requested_table.columnname = 'W/D'
OR requested_table.columnname = 'Done'
OR requested_table.columnname = 'QA Review Dup'
OR requested_table.columnname = 'X' ))
OR ( requested_table.columnname IN ( @Parameter2 ) ) )) )
AND ( ( @ParameterIds = 0 )
AND ( ( ( ( @StartDate IS NOT NULL )
AND ( Cast (@StartDate AS DATE) <>
Dateserial(1900, 01, 01) ) )
AND ( submission.dateimported >= (@StartDate) ) )
AND ( ( ( @EndDate IS NOT NULL )
AND ( Cast (@EndDate AS DATE) <>
Dateserial(1900, 01, 01) )
)
AND ( table.dateimported <= (@EndDate) )
) ) )
AND ( ( @ParameterIds = 0 )
AND (( ( ( @Parameter5 IS NOT NULL )
AND RTRIM(LTrim(@Parameter5)) <> 'All' )
AND ( table.assignedto IN ( @Parameter5 ) ) )) )