Updating a table from SSRS

It’s relatively straight forward to write to a table from an SSRS report once you realise that every time a report is refreshed it tries to run any code it finds in its datasets. This gives us the opportunity to go “off campus”.

Consider a report with a drop-down list called “Change”, containing three choices “View” (the default), “Add”, and “Remove”. And a dataset containing …

    IF @Change = 'ADD'
        INSERT INTO [dbo].[SomeTable]
        VALUES (@Param1, @Param2);

    IF @Change = 'REMOVE'
        DELETE FROM [dbo].[SomeTable]
        WHERE Column1 = @Param1
		AND Column2 = @Param2;

	SELECT * FROM [dbo].[SomeTable];

You could open the report. Paste some values into Param1 and Param2. Choose “Add” from the drop-down. Then click “Refresh Report”.

And maybe limit access 🙂