2010-04-16 28 views
0

我试图把这种水晶报表IF语句的WHERE子句中使用 -如何将此Crystal Report IF语句转换为用于Reporting Services中的WHERE子句?

{@receipt_datetime_daylight} in {?DateRange} and 
(if {?Call Sign} = "All Call Signs" Then 
    {cacs_incident_task.resource_or_class_id} = {cacs_incident_task.resource_or_class_id} 
Else If {?Call Sign} = "All Sierra Call Signs" Then 
    {cacs_incident_task.resource_or_class_id} in ["S10", "S11", "S12"] 
Else If {?Call Sign} = "All Whiskey Call Signs" Then 
    {cacs_incident_task.resource_or_class_id} in ["W01", "W02", "W03"] 
Else 
    {cacs_incident_task.resource_or_class_id} = {?Call Sign}) and 
(if {?OffenceType} = "All Offences" Then 
    {cacs_inc_type.description} = {cacs_inc_type.description} 
else 
    {cacs_inc_type.description} = {?OffenceType}) 

CASE语句不Reporting Services中工作,所以我需要找到一个为什么翻译成WHERE如此条款。有谁知道一种方式?

回答

0

你有三种解决方法:

1 - 创建一个查询,并把这些条件在其WHERE条款。

2-为这项工作创建一个expression并与此一起完成此工作。你可以用BASIC这个语言来写。

3-您可以使用assembly。这意味着您必须以自己喜欢的语言制作dll,并使用报告中的方法。

0

一些工作之后,这里是我的解决方案 -

/* Input Parameters */ 
Declare @StartDate datetime 
Declare @EndDate datetime 
DECLARE @CallSign varchar(50) 
DECLARE @OffenceType varchar(50) 

/* Local variables */ 
declare @CallSignClause nvarchar(1000) 
declare @OffenceTypeClause nvarchar(1000) 
declare @DateClause nvarchar(1000) 
declare @SQLSelect nvarchar(4000) 

/* Test Parameters */ 
Set @CallSign = 'All Whiskey Call Signs' 
Set @OffenceType = 'Burglary' 
Set @StartDate = { d '2010-01-01' } 
Set @EndDate = { d '2010-04-01' } 

if @CallSign = 'All Call Signs' OR @CallSign is null 
    set @CallSignClause = ' cacs_incident_task.resource_or_class_id = cacs_incident_task.resource_or_class_id' 

if @CallSign = 'All Sierra Call Signs' 
    set @CallSignClause = ' (cacs_incident_task.resource_or_class_id IN (''S10'', ''S11'', ''S12'', ''S13'', ''S14'', ''S15'', ''S16'', ''S17'', ''S18'', ''S19'', ''S20'', ''S21'', ''S22'', ''S23'', ''S24'', ''S25'', ''S26'', ''S27'', ''S28'', ''S29'', ''S30'', 
       ''S33'', ''S34'', ''S35'', ''S51'', ''S52'', ''S53'', ''S82'', ''S83''))' 

if @CallSign = 'All Whiskey Call Signs' 
    set @CallSignClause = '(cacs_incident_task.resource_or_class_id IN (''W01'', ''W02'', ''W03'', ''W04'', ''W11'', ''W12'', ''W13'', ''W14'', ''W15'', ''W22'', ''W23'', ''W31'', ''W32'', ''W33'', ''W34'', ''W42'', ''W43'', ''W44'', ''W45'', 
       ''W51'', ''W52'', ''W53'', ''W54'', ''W58'', ''W62'', ''W63'', ''W64'', ''W65'', ''W68'', ''W81'', ''W82'', ''W83'', ''W84'', ''W92'', ''W93'', ''W94'', ''W95''))' 

if (@CallSign <> 'All Call Signs') AND (@CallSign <> 'All Sierra Call Signs') AND (@CallSign <> 'All Whiskey Call Signs') AND (@CallSign is not null) 
    set @CallSignClause = ' cacs_incident_task.resource_or_class_id = ''' + @CallSign + '''' 

if @OffenceType = 'All Offences' OR @OffenceType is null 
    set @OffenceTypeClause = 'cacs_inc_type.description = cacs_inc_type.description' 
else 
    set @OffenceTypeClause = 'cacs_inc_type.description LIKE ''%' + @OffenceType + '%''' 

if @StartDate is null 
    set @DateClause = '' 
else 
    /* set @DateClause = ' ccors_offence.committed_to_date between cast(''' +left(cast(@StartDate as varchar(20)), 12) + ''' as datetime) and cast(''' +left(cast(@EndDate as varchar(20)), 12) + ''' as datetime)' */ 
    set @DateClause = ' DateAdd(dd, 0, DateDiff(dd, 0, cacs_incident_header.at_scene_date)) + DateAdd(dd, 0 - DateDiff(dd, 0, cacs_incident_header.at_scene_time), cacs_incident_header.at_scene_time) between cast(''' +left(cast(@StartDate as varchar(20)), 12) + ''' as datetime) and cast(''' +left(cast(@EndDate as varchar(20)), 12) + ''' as datetime) AND ' 

set @SQLSelect = 
'SELECT 
    cacs_incident_header."id", cacs_incident_header."receipt_date", cacs_incident_header."receipt_time", cacs_incident_header."receipt_daylight", cacs_incident_header."at_scene_date", cacs_incident_header."at_scene_time", cacs_incident_header."at_scene_daylight", 
    cacs_incident_task."resource_or_class_id", 
    cacs_resource."description" as cacs_resource, 
    cacs_inc_type."description" as cacs_inc_type, 
    atscene_datetime = DateAdd(dd, 0, DateDiff(dd, 0, cacs_incident_header.at_scene_date)) + DateAdd(dd, 0 - DateDiff(dd, 0, cacs_incident_header.at_scene_time), cacs_incident_header.at_scene_time) 
FROM 
    { oj ((("universe_db"."dbo"."cacs_incident_header" cacs_incident_header INNER JOIN "universe_db"."dbo"."cacs_incident_header_inc_type_id" cacs_incident_header_inc_type_id ON 
     cacs_incident_header."id" = cacs_incident_header_inc_type_id."id") 
    INNER JOIN "universe_db"."dbo"."cacs_incident_task" cacs_incident_task ON 
     cacs_incident_header."id" = cacs_incident_task."incident_header_id") 
    INNER JOIN "universe_db"."dbo"."cacs_inc_type" cacs_inc_type ON 
     cacs_incident_header_inc_type_id."inc_type_id" = cacs_inc_type."id") 
    INNER JOIN "universe_db"."dbo"."cacs_resource" cacs_resource ON 
     cacs_incident_task."resource_or_class_id" = cacs_resource."id"} 
WHERE ' + @DateClause + @CallSignClause + ' AND ' + @OffenceTypeClause + 
' ORDER BY cacs_incident_task."resource_or_class_id" ASC' 

/* exec sp_executesql @SQLSelect */ 
print @SQLSelect