SELECT column_name, COUNT(column_name) as RecordCount
FROM table_name
WHERE (whatever criteria)
GROUP BY column_name
ORDER BY column_name
Blogged to help me remember and memorize!
100% human-authored articles on software development and technology, since 2006!
Monday, June 01, 2015SQL – Getting the record counts of each distinct value from a table column
Blogged to help me remember and memorize!
Labels:
sql
Monday, April 06, 2015Getting the fractional portion of a number in C#Quick technique for “truncating” the integer portion of a decimal value in C#, leaving only the fractional portion:
Calling that method with the value 12.34 will return 0.34. This works because the modulo operator (%) returns the remainder after dividing the first operand by the second, and any value divided by 1.0 returns the fractional portion of the value. Note that if a negative value is used, the return value (the fractional portion) will also be negative.
Labels:
c#
Thursday, March 19, 2015C#: Default value for int? and other nullable typesIf you’re a C# developer, you’re probably aware of the nullable versions of primitive types such as int? i; And presto, you have an int variable to which you can assign null! Very handy for working with nullable number fields in databases, among other uses. Before today, the above was pretty much the extent of my knowledge of C# nullable types. As far as I was concerned, they were just “magic” versions of the corresponding primitives. I ran into a situation today, though, that led me to investigate more deeply. I had a class with a nullable type field for which no default value was explicitly assigned, as in this simplified example: Class MyClass I needed to determine whether the field had been assigned a value other than the default value. That led me to ask the question: What is the default value for an unassigned nullable Surprisingly, searching Google didn’t immediately lead to a clear answer; nor did there seem to be a question on StackOverflow asking for this particular information. The MSDN article Nullable Types (which was the first Google hit for terms C# nullable default value) didn’t have a clear answer. It was the work of just a couple of minutes to write and run a bit of code to test the behavior using LINQPad. The answer: The default value of a C# So |
| Property | String value |
|---|---|
| AbsoluteUri | https://www.example.com:8080/dir1/dir2/page.aspx?param1=val1¶m2=val2#anchor |
| OriginalString |
https://www.example.com:8080/dir1/dir2/page.aspx?param1=val1¶m2=val2#anchor |
| Scheme |
https |
| Host |
www.example.com |
| Authority |
www.example.com:8080 |
| Port |
8080 |
| AbsolutePath |
/dir1/dir2/page.aspx |
| PathAndQuery |
/dir1/dir2/page.aspx?param1=val1¶m2=val2 |
| Query |
?param1=val1¶m2=val2 |
| Fragment |
#anchor |
The Segments property returns the following String array:
String[] {
"/",
"dir1/",
"dir2/",
"page.aspx"
}
Hopefully this will save a little time for all of you as well as for me!