SQL Server / SSRS - 使用存储过程更新数据

时间:2016-10-12 11:28:42

标签: sql sql-server stored-procedures reporting-services

我有一个存储过程,一旦我将参数放入SSRS报告中,我想根据我放入参数的内容更新列中的数据reason_for_exceptioning,notes和exceptioned。

CREATE PROCEDURE [dbo].[ExceptionOutages]  

  @start_date datetime
  ,@hostname2 nvarchar(max)
  ,@error_flag bit

AS
BEGIN

SET NOCOUNT ON;

UPDATE  PostExceptionMatchingTable      
SET [reason_for_exceptioning] = @reason_for_exceptioning
,[notes] = @notes
,[exceptioned] = @exceptioned

SELECT [client]
  ,[hostname]
  ,[hostname2]
  ,[hostname_2]
  ,[os]
  ,[measure]
  ,[end_seconds]
  ,[start_seconds]
  ,[error_flag]
  ,[end_datetime]
  ,[start_datetime]
  ,[end_date]
  ,[start_date]
  ,[datetime_difference]
  ,[outage_seconds]
  ,[percentage]
  ,[inc_number]
  ,[inc_brief_description]
  ,[inc_status]
  ,[inc_description]
  ,[inc_priority]
  ,[inc_sla_breach_exception]
  ,[inc_sla_breach_reason]
  ,[inc_status2]
  ,[inc_report_date]
  ,[inc_resolve_date_target]
  ,[inc_affected_user_company]
  ,[crq_number]
  ,[crq_brief_description]
  ,[crq_description]
  ,[crq_change_timing]
  ,[crq_start_date]
  ,[crq_end_date]
  ,[crq_outage_start_date]
  ,[crq_outage_end_date]
  ,[crq_priority]
  ,[crq_request_status]
  ,[Expr1]
  ,[wlg_log_date]
  ,[wlg_description]
  ,[wlg_detailed_description]
  ,[submit_date]
  ,[hour_difference]
  ,[day_difference]
  ,[reason_for_exceptioning]
  ,[notes]
  ,[exceptioned]
FROM [availability_outages].[dbo].[PostExceptionMatchingTable]
where [start_date] = @start_date
and [hostname2] = @hostname2
and [error_flag] = @error_flag

END

我不完全确定将更新放在存储过程中的位置

1 个答案:

答案 0 :(得分:1)

您可以将UPDATE放在select语句之前。只要在UPDATE块内,BEGIN..END就可以在存储过程的任何部分中工作。