I have a list of dates, with occasional events that correspond to start and stop dates for periods, and I want to flip a bit switch for all dates which occur between start and stop. Example: (Obviously just a pseudocode example). Is there a way to join these two tables without using a cursor and get the following result: I
Tag: database-cursor
SQL Trigger with loop from another table
I’ve got 2 tables : Table A Table B The table A contains the following values : The Table B contains the following values : My goal is to set the column B.chk with the number of occurence from table A when a new row is created on table B. For example : The trigger on table B should set
How to remove While loop inside stored procedure in MS SQL Server? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year. Improve this question I have a stored procedure with a cursor inside for the logic which is taking long time for execution . I
SQL Server: log database changes through generic trigger
Starting from this article, which is creating a trigger to log insert-, update- and delete-statements within the database, I’d like to create a similar trigger which doesn’t require to define the table and its columns. This would us to reduce human errors when dropping or adding columns. I’ve had many issues (hence the extra code compared to the article) but
Invalid Column Name using Dynamic SQL
I am attempting to use Dynamic SQL for the 1st time – Now i understand the gist of it to an extent however attempting to enter a parameter into a temp table using Dynamic SQL i am getting the “Invalid Column name” when i am simply try to enter this as text not intending to be a column. On a
Open and Close Cursors Inside or Outside a Transaction and How to Close a Cursor if a Transaction Fails
I am writing a stored procedure in SQL Server 2012 that uses a cursor for reading and a transaction inside a TRY CATCH block. Basically, my questions are as follows: Should I declare my cursor inside the TRY CATCH block? If yes, should I declare the cursor before or after the BEGIN TRANSACTION statement? Should I open the cursor before
How to select info from row above?
I want to add a column to my table that is like the following: This is just an example of how the table is structured, the real table is more than 10.000 rows. So for every time there is a value in ‘Subgroup’ I want the (New_Column) to get the value [No_] from the row above There are cases where
SQL Server – Cursor
I am trying to loop through a table using a cursor: That above returns taskResourceOID and EvUserOID. If I need to output a table with the @TaskOID and the respective taskResourceOID and EvUserOID, what is the best way to do it? Answer Use a temporary table or a table variable.. Or even better, don’t use a cursor (this can be
Reset or Update Row Position Integer in Database Table
I am working on a stored procedure in SQL Server 2008 for resetting an integer column in a database table. This integer column stores or persists the display order of the item rows. Users are able to drag and drop items in a particular sort order and we persist that order in the database table using this “Order Rank Integer”.