Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Non cursor based looping within a script.

$
0
0
I have a script that I am trying hard not to use a cursor for.The script will insert values into a table, but I have the following scenario.Lets say the table I wish to insert into has four columns. 1. Id [INT]2. UserID [INT]3. RefID [INT]4. NewValue [VarChar(20)]What I wish to do is create a script whereby I can in effect do the following:INSERT INTO [Table] (UserID, RefID, NewValue) Values (@UserID, @RefID, 'Fixed message')And the script will use:SELECT @UserID = UID, @RefID = RefID From UserTable Where <Some condition>.Now the above is easy with a cursor, but with 1.9 million records to process it is estimated to take 2.5 days to complete.So I have looked into creating a temp table holding the base data and looping around this temporary table. It is quicker than a cursor, but not by much.There must be a better way of doing this.

Viewing all articles
Browse latest Browse all 3145

Trending Articles