SQL Server trigger code
-
DECLARE p_cursor CURSOR FOR
SELECT TOP 1 SortDateStart AS DateStart, SortDateEnd AS DateEnd
...This code was in a trigger... :omg:
-
DECLARE p_cursor CURSOR FOR
SELECT TOP 1 SortDateStart AS DateStart, SortDateEnd AS DateEnd
...This code was in a trigger... :omg:
What especially are you considering to be a horror? 1. Using a database trigger at all (this is IMHO the true horror here :sigh: ) ? 2. Using
TOP 1
without being explicit about it ? Regards Thomas_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
What especially are you considering to be a horror? 1. Using a database trigger at all (this is IMHO the true horror here :sigh: ) ? 2. Using
TOP 1
without being explicit about it ? Regards Thomas_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
Well, I am ok with triggers so far you make a sensible use of them (which is not the case for the database where I found this). You should avoid the use of cursors with SQL Server, that is not good but most people would not call that an horror. The point is: Why on earth would someone open a cursor on a 1 row set???? In this case it is far more simple and efficient to type: SELECT TOP 1 @A=Column1, @B=Column2.... instead of declaring a cursor, fetch the data and close it.
-
What especially are you considering to be a horror? 1. Using a database trigger at all (this is IMHO the true horror here :sigh: ) ? 2. Using
TOP 1
without being explicit about it ? Regards Thomas_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
Ah, now I get it... Sorry, I'm not very familiar reading such things. So I missed the point... :doh: Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
Well, I am ok with triggers so far you make a sensible use of them (which is not the case for the database where I found this). You should avoid the use of cursors with SQL Server, that is not good but most people would not call that an horror. The point is: Why on earth would someone open a cursor on a 1 row set???? In this case it is far more simple and efficient to type: SELECT TOP 1 @A=Column1, @B=Column2.... instead of declaring a cursor, fetch the data and close it.
Arnaud Lhopiteau wrote:
The point is: Why on earth would someone open a cursor on a 1 row set?
Not sure. Perhaps it was a rush job at the end of a Friday afternoon and they forgot what they were supposed to be doing?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham