I am going through some old stored procedures at work and came across constantly
< Code> case is my column 'y' then 'yes' when 'n' then 'no' or 'unknown' end
It is not connected to a word, but instead a color .
Case MyColumn WHEN 'Y' then 'style = "background color: pink"' ELSE '' END
This was because the old ASP For 1 pages, where everything was to be inlineed, but as a large system, updating all the pages is impossible and it is impossible to continue.
Does anyone provide a valid proof that uses SQL queries are best in conditional statements in other languages like C # or Java? Is this a good practice for speed? The plain value should be returned and the presentation level should be fixed what should be done?
Abstract, the details of the SQL case may also be the fastest (I will run a test), but maintainability For example, simplicity values are the best option to return to the presentation layer (or some business layer thingy).
[Update] Run some quick and dirty test (code given below) and C # code type sql Found slightly faster than the case version Conclusion: Both are faster and stronger by returning the 'raw' data and adding it to the presentation level.
-Edoode
I retrieved 196288 rows with the following questions.
stringbilder result = new stringbilder (); (Using SqlConnection conn = new SqlConnection (Settings.Default.Conn)) {conn.Open (); String CMD = "Selection [state], case [state] when 'ca' then 'California' and [state] end with member"; SQL Commands Command = New SQL Commands (CMD, Con); (Using the SqlDataReader Reader = command.ExecuteReader (CommandBehavior.CloseConnection)) {reader.Read ()) {result.AppendLine (reader.GetString (1)); }}}
C # version:
stringbilder result = new stringbiller (); (Using SqlConnection conn = new SqlConnection (Settings.Default.Conn)) {conn.Open (); String cmd = "select [state] from member"; SQL Commands Command = New SQL Commands (CMD, Con); (SqlDataReader reader = command.ExecuteReader (CommandBehavior.CloseConnection)) {while (reader.Read ()) {result.AppendLine (reader.GetString (0) == "ca"? "California": reader.GetString (0)) ; }}
}
Comments
Post a Comment