Loop through all the rows of a temp table and call a stored procedure for each row

you could use a cursor: DECLARE @id int DECLARE @pass varchar(100) DECLARE cur CURSOR FOR SELECT Id, Password FROM @temp OPEN cur FETCH NEXT FROM cur INTO @id, @pass WHILE @@FETCH_STATUS = 0 BEGIN EXEC mysp @id, @pass … — call your sp here FETCH NEXT FROM cur INTO @id, @pass END CLOSE cur DEALLOCATE … Read more

Splicing a Javascript array from within the callback passed to forEach

Lets see why JavaScript behaves like this. According to the ECMAScript standard specification for Array.prototype.forEach, when you delete an element at index 1, the element at index 2 becomes the element at index 1 and index 2 doesn’t exist for that object. Now, JavaScript looks for element 2 in the object, which is not found, … Read more

Add a delay after executing each iteration with forEach loop

What you want to achieve is totally possible with Array#forEach — although in a different way you might think of it. You can not do a thing like this: var array = [‘some’, ‘array’, ‘containing’, ‘words’]; array.forEach(function (el) { console.log(el); wait(1000); // wait 1000 milliseconds }); console.log(‘Loop finished.’); … and get the output: some array … Read more

Why does the local variable of an enhanced for loop have to be local? [duplicate]

Look at how the for-each loop internally works, see How does the Java ‘for each’ loop work? for(Iterator<String> i = someList.iterator(); i.hasNext(); ) { String item = i.next(); System.out.println(item); } Each time it declares the String variable item. Hence in your case its doing essentially State state; \\and inside State state = i.next(); which obviously … Read more

Nifty way to iterate over parallel arrays in Java using foreach

I would use a Map myself. But taking you at your word that a pair of arrays makes sense in your case, how about a utility method that takes your two arrays and returns an Iterable wrapper? Conceptually: for (Pair<K,V> p : wrap(list1, list2)) { doStuff(p.getKey()); doStuff(p.getValue()); } The Iterable<Pair<K,V>> wrapper would hide the bounds … Read more

In java8, how to set the global value in the lambdas foreach block?

You could, of course, “make the outer value mutable” via a trick: public void test() { String[] x = new String[1]; List<String> list = Arrays.asList(“a”, “b”, “c”, “d”); list.forEach(n -> { if (n.equals(“d”)) x[0] = “match the value”; }); } Get ready for a beating by the functional purist on the team, though. Much nicer, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)