I imported a report from Crystal to SSRS.
When I run the query in Microsoft Management Console, it throws errors unless I declare variables before the SELECT statement. When I run the query from Visual Studio, it bypasses these variables and only throws an error on the TRIM function.
From what I can tell a JOIN statement may be used instead of a TRIM, but I am not sure.
This is the portion of a where clause that I am trying to change/adapt to work with SSRS, which is throwing an error -- any suggestions appreciated.
Also, I am having issues with the DateSerial in the WHERE clause as follows:
AND (CAST(@StartDate AS Date) <> DateSerial(1900, 01, 01)) AND
Trim does not work in SQL only in the report expressions you would have to use LTrim and RTrim to make this work.
AND ( ( NOT ( @Status IS NULL )
AND RTrim(LTrim(@Status)) <> 'All' )
(( ( RTrim(Ltrim(@Status)) = 'Completed' )
AND RTrim(LTrim(@AssignedTo)) <> 'All' )
AND ( submission.assignedto IN ( @AssignedTo ) )
INCLUDING THE ENTIRE WHERE CLAUSE:
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 ) ) )) )
Fix the Dateserial and this should work.
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 ) ) )) )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.