Growing up in Wisconsin I became very familiar with winter, ice and the freezing cold.
some things about winter have a bit of magic to them. Ice Shoves are one of those things.
As a kid they where a place to test your balance, strength and persistence to climb to the top. They also made magical noise as the water moves the chunks of ice.
Apparently unknown to my childhood adventures they also did much damage to property.
Here are some photos I found on the web.
http://www.uwgb.edu/dutchs/GeologyWisconsin/weather/ICESHOVE.HTM
If I make it back to the lake I grew up on I plan to take some photos if the timing is good.
I was looking for a way to get a count of two tables that shared the same structure and both used an account number in the where clause.
my database has one record in one table that has account number of ’123′
This code return two records, 1,0 in my case
|
|
declare @Account varchar(20);
set @Account = '123'
select count(*) as mycount From tableone where accountNumber = @Account
union
select count(*) as mycount From tabletwo where Accountnumber = @Account |
The secret is to select from the union and using the union as the “FROM” part of your query.
This is the T-SQL to get it done with SQL-2005
In this instance I get one row with the sum or total of the two count requests. That value is 1.
|
|
declare @Account varchar(20);
set @Account = '123'
select sum(mycount) from
(
select count(*) as mycount From tableone where accountNumber = @Account
union
select count(*) as mycount From tabletwo where Accountnumber = @Account
) as myUnion |
VB.NET Code:
|
|
Dim sql As String
sql = "select sum(mycount) from ( select count(*) as mycount From table1 where accountNumber = @Account union select count(*) as mycount From tabletwo where Accountnumber = @Account) as myUnion"
Dim recCount As Integer = 0
sqlcn.Open()
sqlCmd.Connection = sqlcn
sqlCmd.CommandText = sql
sqlCmd.Parameters.AddWithValue("@Account", myAccount)
sqlReader = sqlCmd.ExecuteReader()
sqlReader.Read()
recCount = sqlReader.GetValue(0)
... |