# A result set was generated for update - SQL Query

**URL:** <https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338>\
**Category:** Ignition\
**Created:** [April 29, 2013, 8:21am UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338 "2013-04-29T08:21:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pat.stave](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@pat.stave](https://forum.inductiveautomation.com/u/pat.stave)\
**Post date:** [April 29, 2013, 8:21am UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338/1 "2013-04-29T08:21:09Z")

</div>

The following query runs fine in SQL Server Management Studio; but when i try to run it in Ignition it generates the following error:  
“Error running query: A result set was generated for update.”

The server contains several databases, so setting the nocount option in server settings would probably affect the other databases running on the server.  
Ref: [viewtopic.php?f=25&t=5920](http://www.inductiveautomation.com/forum/viewtopic.php?f=25&t=5920)

I have also tried to use “SET NOCOUNT OFF;” in the first query line, with no results.

```auto
-- Decleare the start and end dates
DECLARE @tStart datetime;
DECLARE @tStop datetime;
SET @tStart = '2013-04-25 14:00:00';
SET @tStop = '2013-04-25 15:30:00';

-- Variable that holds the indexID to the row closest to the start time
DECLARE @rStart int;
-- Set the content of the variable
SET @rStart = (
       SELECT TOP 1 [nordlaks_produksjon_slakteri_sloyelinje_produksjonstall_ndx] 
       FROM [IgnitionHistorian].[dbo].[Nordlaks_Produksjon_Slakteri_Sloyelinje_Produksjonstall]
       WHERE Datediff(SECOND, @tStart, t_stamp) > 0
       ORDER BY Datediff(SECOND, @tStart, t_stamp)
);

-- Fetches the first row after the end time and merges it with the first row after the start time,
-- Then calculates production count.
SELECT TOP 1 
       r2.[t_stamp] AS From,
       r1.[t_stamp] AS To,
       r1.[M1Total] - r2.[M1Total] AS [M1Prod],
       r1.[M2Total] - r2.[M2Total] AS [M2Prod],
       r1.[M3Total] - r2.[M3Total] AS [M3Prod],
       r1.[M4Total] - r2.[M4Total] AS [M4Prod],
       r1.[M5Total] - r2.[M5Total] AS [M5Prod],
       r1.[M6Total] - r2.[M6Total] AS [M6Prod],
       r1.[M7Total] - r2.[M7Total] AS [M7Prod],
       r1.[M8Total] - r2.[M8Total] AS [M8Prod]
FROM  
       [IgnitionHistorian].[dbo].[Nordlaks_Produksjon_Slakteri_Sloyelinje_Produksjonstall] r1
       LEFT JOIN [IgnitionHistorian].[dbo].[Nordlaks_Produksjon_Slakteri_Sloyelinje_Produksjonstall] r2 
             ON r2.[nordlaks_produksjon_slakteri_sloyelinje_produksjonstall_ndx] = @rStart
WHERE
       Datediff(SECOND, @tStop, r1.t_stamp) > 0
ORDER BY 
       Datediff(SECOND, @tStop, r1.t_stamp)
```

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [April 29, 2013, 5:53pm UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338/2 "2013-04-29T17:53:26Z")

</div>

Where are you trying to run it from? Wherever it is, it is trying to run it as an “update”, when you really want it to run like a select. You’ll likely need to use the [system.db.runQuery](http://inductiveautomation.com/support/usermanuals/ignition/system_db_runquery.htm) scripting function or something similar. And in that case, it’ll probably be easier to wrap it up in a stored procedure and just call that.

Regards,

---

<div class="post-metadata">

**Author:** ![pat.stave](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@pat.stave](https://forum.inductiveautomation.com/u/pat.stave)\
**Post date:** [April 29, 2013, 6:03pm UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338/3 "2013-04-29T18:03:36Z")

</div>

I was running the query from the query console in the designer.  
Upon reading your post i tried to move the query to the component binding (where it was supposed to run anyways).

And guess what; everything worked beautifully 🙂  
Been fiddling with this in the query console for days, and that was the only problem 😆

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [April 29, 2013, 6:23pm UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338/4 "2013-04-29T18:23:16Z")

</div>

Yeah, I suspected that. Behind the scenes we have to decide whether it’s going to be a query or an update, and the query browse just does a basic check on the first keyword to decide, which doesn’t work for things like this.

Glad you got it working,

---

<div class="post-metadata">

**Author:** ![olivier.cote](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@olivier.cote](https://forum.inductiveautomation.com/u/olivier.cote)\
**Post date:** [November 7, 2024, 6:28pm UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338/5 "2024-11-07T18:28:09Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/3/03bee9469be4b0388e3bd6b9fdd90fe8b90acf5d.png)

I had a similar issue and realised that in the tag properties, you can have  
AutoDetec  
Select  
Update

Mine was in Autodetect. Since I was calling a Stored Procedure, the Autodect was picking 'Update'. Since I know that this SP is only doing Select, I could set to to 'Select' and it solved my issue!

(if it can help someone)

---

<div class="post-metadata">

**Author:** ![Brady\_Boyd](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@Brady\_Boyd](https://forum.inductiveautomation.com/u/Brady_Boyd)\
**Post date:** [January 2, 2025, 5:04pm UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338/6 "2025-01-02T17:04:39Z")

</div>

This helped me when trying to run an INSERT statement as a named query. When calling the named query to add a task to my task manager, it would INSERT as expected, but I kept getting the "A result set was not generated" error over and over.

After changing my Query Type from Query to Update Query, I stopped having that issue.

Thank you!

---

<div class="post-metadata">

**Author:** ![mcaya](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mcaya](https://forum.inductiveautomation.com/u/mcaya)\
**Post date:** [January 14, 2025, 6:23pm UTC](https://forum.inductiveautomation.com/t/a-result-set-was-generated-for-update-sql-query/6338/7 "2025-01-14T18:23:54Z")

</div>

Hello, did you try to remove all the comments ?  
I had some problem like this before.
