Tuesday, July 1, 2014

Emotional Maturity

Your emotional stability is directly tied to your awareness of other's needs.

Think of children, they're emotionally volatile because they're completely self-absorbed. Their emotional state is never adjusted to account for those around them.

Now see the other end of the spectrum, Jesus endured the most self-deprecating experience possible because of the joy that was set before Him (Heb 12:2). His joy was knowing the way to God would be made available by His sacrifice. His emotional state was completely balanced by His awareness of others.


Maturity is simply being aware of and attending to the needs of others around you.

Friday, March 14, 2014

Love's Moment

I don't think I've ever watched a more moving advert than a Portugese ad by LG - Momentos. 

The sidewalk offered little comfort against the chilly night, his blankets made a poor bed. At least the store with a For Lease sign in front of the brown paper covering its windows had no owner or activity to drive him away. This night however was different, two men pulled up in a white van, carried three LG TV's and put them in the window. He cracked an eye to watch but didn't really care. They turned on the TV's, pulled down the paper and left. The light caught his attention and he sat up to watch. Two other homeless men joined him, they laughed at the scenes but the two were annoying and he drove them away. Sad and alone again he continued to watch.

Observing his attention, a controller in a parked car made a call, TV's flicker and suddenly he was watching himself. Surprised, at being on TV and by his appearance, he touched his beard, surprised at how long it had grown. After a moment someone drops in a DVD, once again the TV's flickered but this time it was his life. His wife, his daughter, Christmas, opening gifts, they were much younger, he was clean shaven and they were all laughing. The images began a subtle work as they softly shone love's pure light into his hardened heart. At first a faint smile, then tears, his daughter holds out a flower to the camera and he instinctively reached toward the TV for it.

At that moment, the van rolls up again, a man walks out of the store and into the van, the homeless man turns to look. Two people got out on the far side of the van, it pulls away to reveal his wife and daughter. A much older daughter, in her early twenties, carrying a teddy seen in the Christmas scene. Electric emotions filled the air. The daughter's love is tangible as she longingly looked at her father, the wife hesitated, motionless between hope and rejection.

These are the moments all of us face, we all make mistakes, we hurt people and people hurt us. We drift off course and like the homeless man, we find ourselves away from home and not sure if we're welcome back.

His daughter's love was tangible, it reached out, his heart was kindled but self doubt was present and he faced the greatest struggle of his life. His feet shuffled backwards, love drew his heart but failure resisted. He was unsure what to do.

Love does the same to us. It confronts our condition, it reveals our reasons and that's the problem with love. It's confrontational, it's active, it doesn't turn a blind eye or look away, it stares straight into the depth of our heart, removes all the excuses and calls us to action. It's more powerful than all of our failings but on its own it's not enough, one more ingredient is necessary. It requires hope. Without hope love is short circuited into a temporary fix. Hope gives honor to the giver and breaks the cycle of selfishness. Unless hope is kindled the giver will be betrayed and the cycle of hurt deepened.

Hebrews highlights the same concept with "Faith is the substance of things hoped for, the evidence of things not seen." Hope is the hanger upon which faith is hung. Without hope, faith doesn't work. A man without hope cannot respond correctly to love. Hope then is the very fabric of change and what moves a man from stagnation to success.

On a cold sidewalk, love met hope, the daughter ran to her father, his hesitant arms slowly embraced his daughter, his wife drew in as she embraced them both and smiled as he started his journey home.

Sunday, March 9, 2014

Trap and Win

My three year old boy loves to find me in the house, lie at my feet and yell "Trap!" I straddle him tightly and see if he can wriggle free. If he can't, he begins to cry but I've learnt it's as fake as whipped topping or rhinestone jewelry because the moment he gets free, he laughs and yells "Trap!" Now when he starts to cry, with fatherly encouragement I tell him "Fight! Come on, get free. You can do it!" He presses hard, I shout some more, he's not sure if he can win but he struggles to freedom - a sweeter victory than if I'd played easy. 

It's a fun game but I have a deeper purpose. It takes guts to win in life. The myriad forms of resistance cause us to either whine or dig deeper. I want him to win, so it's a simple game but I'm determined to teach my boy he can win in every circumstance, even when it seems impossible.

Wednesday, December 4, 2013

Modern Indulgences

I have a question for you. In the middle ages the church was known for selling indulgences. Purchasing an indulgence took care of two needs. The first was a punishment for your sins, a way to make you feel bad for offending God. The second, a way to reduce your debts of sins in purgatory. Purgatory was a place after death where you paid off your sins. This strategy was marketing genius, a consistent revenue stream and overall hideous idea.

It relied on failing to see Jesus as the price paid for all sins and faith as the way to obtain forgiveness. It was in essence a material way to earn a spiritual blessing.

When we look at Jesus we never see anyone offer Him money for forgiveness or healing. The example continues with the apostles and nothing is ever exchanged for a miracle. Jesus said "Freely you have received, freely give."

Do you think the modern church deals in indulgences?

If healing and forgiveness are free, why is there such a culture of "Wrap your seed around your need."? Where is the New Testament example of giving related to a miracle? It's very easy to see the errors of the medieval church. Forgiveness was perceived as difficult to receive and money was a way to earn forgiveness, yet we know it's as simple as believing. Why do we think it necessary to give in order to receive? Isn't it as simple as belief?

The bible details a very clear example of giving to receive. Paul said with the same measure that you give you will receive but he clarifies what you receive. He said "men will give into your bosom" that means money. If you need money, sow. The bible is expressly clear on that. The church should also be expressly clear on the fact that it needs money to run. If you don't give, your church can't pay the light bill. The last time I checked you couldn't pay your power bill with happy smiles.

What drives this message of money for miracles? I could guess but one thing I know, it doesn't take your money + Jesus to get a miracle. Jesus is sufficient all on His own. In fact the man credited with having great faith in the gospels put forth the least amount of human effort. He resisted Jesus coming to his house and simply said "Speak the word and my servant will be healed." The least amount of human intervention brought the maximum amount of divine intervention.

So what do you think of wrapping your seed around your need? Is it biblical or indulgent?

Thursday, November 21, 2013

Rain


Living on the mountain we have no city water and depend on the rain. We have a main tank for the house and a small one for plants. I filled a couple of buckets from the smaller one for my son to play with today. At three, he loves the water. He pours it on the plants, the chairs, over the side of the deck or simply tips the bucket upside down for fun. It was hard as a parent to watch the waste without intervening but it's an essential part of play and I let him be.

I was struck with the comparison that God has given us this world "hands off". We have total reign over His precious creation, including us. How would we act if we were keenly aware of His watchful eye? Would we be so cavalier or might there be a greater appreciation of all He has given us and a hesitation to mistreat His creation and creatures?

Photo copyright US Air Force - Technical Sergeant Mike Buytas

Friday, October 11, 2013

I live on the edge of the rainforest, every day there's a fight here. A fight for the rainforest's most valuable commodity. Sunlight. Water is in abundant supply but sunlight is almost impossible for seedlings to find. Occasionally a giant tree may fall leaving a brief moment for the most aggressive to dominate but it's a tough fight on the forest floor. One fig wins the battle in a most underhanded way. When a bird or lizard eats fruit from the Strangler Fig some of the seeds get deposited in crevices at the top of huge trees, giving them direct access to sunlight. Over a long period of time the fig sends down fine roots. When they reach the ground the plant kicks into a growth spurt, sending down additional roots and growing leaves. The root network encircles the tree above and below ground, strangling its roots and trunk. The host tree eventually rots out from the fig leaving a twisted hollow reminder of the tree on the inside.

As we journey through life there are seeds of thoughts which are dropped in our minds. Some of those thoughts are aggressive, bitter thoughts. They often stem from real offenses, and may be justifiable. If left unattended, like the Strangler Fig, they overtake and begin to strangle us, cutting off who we used to be. Crippling our lives with bitterness and pain, leaving a hollow, distorted image of who we once were.

Forgiveness gently removes those seeds and their roots. It's not about the perpetrator, it's ultimately about us. Forgiveness returns us to who we truly are. Removing bitterness can be hard work, there's something sickly attractive about it. It just feels good to nurse. Forgiveness is not about saying that what was done was OK, it's about letting love win. Bitterness is like drinking poison waiting for your enemy to die. Put the cup down and begin by simply saying the words "I forgive" If you're faithful to press in, real forgiveness will come and you'll return to the authentic you, nothing could be sweeter.

Some offenses are very graphic, if you find it hard, locate someone who can help walk you through the process.

Thanks to Pastor Greg for the fig tree example.

Thursday, October 3, 2013

Isolating Trouble

From the beginning of time man has been discovering and isolating elements and chemicals. 6000 years ago man discovered how to extract iron, in 1933 Walter Haworth isolated Vitamin C. When these essential components were in their natural environment their properties were much harder to interpret. Once isolated they became much easier to interact with and understand but these discoveries do not come easily, the journey to isolate Vitamin C took over 25 years.

In a similar way, we are complex beings, an intricate weaving of upbringing,experience and environment. There are many interactions happening inside us, some good, some not. A particular reaction to an event may have a single source but like iron or Vitamin C in their original environment, that source is difficult to see when mixed with all our other thoughts and emotions. If one is brave enough, it's incredibly valuable to take the time to sort through the myriad of internal interactions and get to the core thought. Isolating this thought may take significant time and effort but once isolated it becomes much easier to understand. At this point both the thought's effect and origin can be determined. If the effect is determined one is able to identify the feelings associated with that thought. Being aware of the thought and it's feelings become an early warning system that allows one to avoid the thought before it takes us over. Understanding the origin of the thought gives a method to undo the very root of the problem.

So next time your reaction catches you off guard or your behaviour is not becoming, get a trusted friend, sit down, get honest, and dig into the details. Pull each layer of thought apart until you get to the core. You'll simply know when you get there and with that thought isolated you will see a clear way forward.

Thursday, March 21, 2013

Handle with Care


Today I met a new leader at Bethel, well met isn't really the right term, that would imply a meeting, this was a counseling session. Those are a lot of fun, sort of. You can imagine a nice comfortable setting with the counselor to whom you're about to bear your soul but here you have to add 12 interns learning from the process. Fun isn't quite the right term but it'll do for now.

As you may know my wife passed away five years ago and the circumstances preceding her condition/illness were not the best. As a result I've had a couple of seasons of counseling. If you've ever wondered about counseling I have one question for you, would you like to work through a problem at your pace or would you like someone to accelerate that processing time? If you want to work it out on your own, go ahead.

So I sat before the group, ready to bear my heart because I realized I could say nothing and that's exactly what would happen or I could seize the moment. So I cracked a few jokes to ease the tension and dove in. 

I began following a familiar line of discussion, laid a foundation for all to understand the heart of the issue and then said one word which turned the next hour completely upside down.  As I described everything I hit a word I'd never connected before, the accuracy and intensity of it unglued me in an instant. In all of the previous counseling I'd never been emotional about the subject. I was simply tied shut over it. It had been impossible for me to cry, I was locked up but release was about to come. That one word broke me as I because I'd never connected it to the centrality of my situation. 

From there the session was simply the most incredible exposure and revelation; care and restoration I think one could have. You place someone with a lifetime of pain whom the Holy Spirit has been priming and making ready for redemption in the hands of the most tender, caring, spirit led leader I have ever met and you can only imagine what happens.

This is not just ask a question, get an answer, then process. This is the counselor saying "I see this...", "I see this...." one by one describing the internal prisons, why they were locked and how to get free. I understood why his words were so penetrating when he said "Jesus knows, I've seen Him, He knows."

His tenderness was beyond anything I've ever experienced; his comfort and compassion were redemptive in and of themselves. The moment I cracked at the first word he was at my side on his knees. The Holy Spirit is a dove and He was allowed to manifest in the most sensitive nature of that expression. I am full of thanks for such skillful care of the human heart, the most valuable of all earthly treasures.

Monday, March 11, 2013

Which side are you on?



I recently learned that the word enthusiasm comes from two Greek words, en and theos. En is the word "in" and theos is the word "God", so enthusiasm means "In God." When I read that I thought "Yes!" When I'm "In God" there is a burning enthusiasm that energizes every part of my life. The closer I am to God, the more I burn with joy.

The opposite is also true and like the Force in Star Wars, there's a Dark side. It competes against the Light for my attention and affections. The more I slide to the captivity of the Dark side the more I manifest it's non-enthusiastic expressions of depression, doubt, questioning and complaining.

The good (and bad) news is I'm not stuck, I can always move. The more I allow God to captivate my affections the more enthusiasm I experience; the more I yield to Dark affections the heavier my heart will be. I'm sticking on the Light side.

Monday, February 18, 2013

Ravi and the Incense Factory


I've spent the weekend listening to Darren Wilson, creator of the Father of Lights movie (he's the guy in blue) and he told us a story about Ravi you've probably not heard. You might ask "Who is Ravi?" Ravi is a guy in India to whom God speaks audibly every day. Each morning about 4am God wakes Ravi up and tells him what He wants him to do that day. Pretty crazy! Needless to say amazing things happen.

One of the things Ravi does is minister to widows and orphans in India. Being a widow is especially tough in India because their culture holds that if your husband died, he died because you are cursed. You are thrown out of society, left to fend for yourself and become an untouchable. Pretty bad stuff.

In one city where he ministers to widows they have a camp on the outside of town where they live. Ravi thinks, it would be great to get some work going to raise the status of the women. He knows they can all sow, so he buys a bunch of material and has them sew cushions. They begin, things ramp up, they sell some cushions but by the second month things are beginning to stall. Sales are dropping off, some women move away and things simply grind to a halt.

Disappointed, Ravi talks to the Lord and says "What's up? I'm here trying to help these ladies and nothing's working?" 
The Lord replies "Did you ask me what I want them to do?"
"Ummm, no."
"Are you ready to ask Me what to do?"
Sheepishly Ravi responds "Yes..."
"I want them to make incense."
Ravi exclaims "God, this is India, they don't burn incense to make houses smell nice like they do in America. They burn incense to worship idols, you know like demons..."
"I want them to make incense."
"Ok"

So Ravi works out how to make incense, gets all the materials and then God gives him one extra instruction. "I want the women to pray over the materials for 1/3 of the day and make the incense for the other 2/3 of the day." They set to praying, making and selling the incense as the Lord directed them to.

About two weeks go by and there's a knock on the door. They answer and it's people from the nearby village. They ask them what they want and they reply "We want to talk to the people who make this incense; odd things are happening."
"That's us, what's going on."
"We've noticed that every time we burn your incense our idols fall over or mysteriously get broken and our children are seeing angels and demons in our houses. We want you to bless us because you have something powerful!" Now the women have prestige and honor in the city. Whenever a child is born they bring the child to the women to bless because they know a powerful God is with them!

Sunday, January 13, 2013

Falling Up

There are three places I call home, Australia, Columbus, Ohio and Redding, California. I returned to Columbus for Christmas and the highlight of my visit was falling up.

I've been in bible school for the last six months and loving it. This bible school is distinctive in that it's primary focus is teaching us to flow in the supernatural gifts of God, such as those outlined in 1 Cor 12. Like all things that require repetition to learn, skill comes from practice. The gifts are no different but it takes both practice and faith to walk in them. Not only that, you have to embrace the idea that faith is often spelled R-I-S-K. Risk is often the prerequisite for success. The same is true in many areas of life, an investment that exploded or a relationship that blossomed first required risk. The greater the risk the greater the reward and so a confrontation with risk became the highlight of my trip.

I need to back track for a moment. A few days after arriving my dear friend Scott invited me to speak for five minutes at a Sunday evening prayer meeting. After the meeting another friend, very seasoned in the Lord said, "I hear the Lord say, if you continue in humility, fervency and love. He will open a door for you to minister to youth." Not something I'd done much before but I realize the incredible potential in developing young people.

Fast forward to a few days before the end of the trip and someone who had been reading my Facebook posts suggested to the youth pastor of her kids that I minister to their youth group at one of the larger ministries in town. Now adults I get, when I say something, I know the internal response those words are going to create. Youth, I have no idea, they scare the kajoobies out of me. If you know what a kajoobie is let me know because I just lost all mine.

So with significant trepidation I prepared for the message. While writing down my thoughts I heard the name Melissa and saw a picture of the Lord picking up a gem and placing it in the crown of our Savior. I've seen people at my school, call out a name and then give a word from the Lord but I'd never done that. So this is a new level of risk for me. Before the meeting I was tempted to ask some friends in the group, "Is there a Melissa in youth group?" but I resisted and went on to preach.

I was telling the youth how natural it is to flow with the Holy Spirit. It's easy to talk to a friend, He wants to be our friend; build a relationship with Him and it's easy and quick to talk to Him. It's natural to respond to His voice but it requires risk. You have to be prepared to fail, without that willingness, nothing is going to happen. So I said "Let's try it right now. Is there a Melissa in the room?" Waiting, waiting, waiting... "Nope! See how simple that was, I tried and failed. I really believe the Lord wanted you to see someone fail and know it's OK. It's like falling upwards, you go, you try, you fail and you learn." It was so much fun to be a real life example of attempt and failure because it took the pressure of performance away. It gave them the freedom to say "If he tried, failed and laughed. I can do the same."

Of course everyone and myself was delighted when Melissa walked in the room ten minutes later! I told her she was a hand picked gem, and to seek out others to place in His crown. The neat thing for one of the youth was he had watched that word being given in a dream two nights before!

Break out of your comfort zone into a new level of risk. Failure stinks but it's much better to tear through the thin veil of risk that separates you from the things you desire, because once you try the next time only gets easier.

Monday, December 17, 2012

Coming Home

We love growth. You've seen the door post with short pencil marks, measuring the family tribe as each child grows. Everyday they check to see if they're taller but change is incremental and that's why we have record it. Coming back home is like encountering those old marks on a door post. I've been in school three months out of six away and there was this pressure as I returned home for Christmas. Was moving all the way across the country worth it? If I'm honest there's been internal pressure to be super powered and coming back was pressured. I know better than to yield to the pressure but it can be challenging.
So returning home causes me to ask the question. What's changed? The biggest thing is knowing God is pleased with me. As my Father He's crash hot about me and His Son thinks I rock. That's not a proud or arrogant statement, it's simply knowing that God loves me. What's even better, is it isn't about how well I do things, His love isn't about performance. What father causes his children perform before he loves or enjoys them? He simply wants his children in his presence.
Living in that reality brings a profound change in life. No longer am I striving to perfect every last shred of my life before I receive His acceptance. Maybe you think He requires your perfection, or that your sins have separated you from His presence. That's scripture but let me ask you, are you seeking Him with all your heart? If so then I would refer you to "Love covers a multitude of sins." Paul tells us we have junk but the solution is to reckon or decide not to yield to it. He tells us what we think is key to how we live. Do you want to live more? Believe that God's grace and acceptance is greater than your sin.
God is not looking for you to work out your hardest problems before He receives you. He's waiting for you to invite Him into your deepest mess. Get up on His lap and invite Him to help you work it out. As you do believe that His grace is bigger than you sins and experience His royalty at work in you. So I sum up the last six months in a message from a friend I caught eyes with on Sunday, "Your countenance lifted my spirit!" The radiance of your face comes from deep inside. The more you live in the reality of God's grace upon your life, the brighter your countenance.

Wednesday, November 28, 2012

Into the box

J Allen Peterson makes a profound statement "Most people get married believing a myth - that marriage is a beautiful box full of all the things that they have longed for - companionship, sexual fulfillment, intimacy, friendship. The truth is that marriage, at the start is an empty box. You must put something in before you can take anything out. There is no love in marriage, love is in people. There is no romance in marriage, people have to infuse it in their marriages. A couple must learn the art and form the habit of giving, loving, serving, praising - keeping the box full. If you take out more than you put in, the box will be empty."

That's amazing advice for couples but it pertains to our relationship with God as well. Many people bring their box to God and say "Fill it up, Lord." It's good to have Him fill it but did you know God wants you to put your heart and emotions in it as well? He's looking for more than obedient servants, He's looking for relationship. He created you for more than servanthood, He created you for fellowship. You have stuff to put in the box and He wants it, He's interested in your ideas, thoughts and friendship.

In the Old and New Testaments God called Abraham His friend; friends talk, friends exchange ideas and challenge each other. Abraham's friendship was expressed in Gen. 18 when he interceded on behalf of Sodom. Contrary to God's plan he pleaded for the people of Sodom and God listened. The relationship wasn't about Abraham's goodness, he lied about his wife over and over and by his poor decisions fathered both the Arab and Jewish people. Through that mix alone he is personally responsible for messing up half the planet, yet he's still considered a friend of God. I doubt you've messed up half the planet so there's hope for you!

Over and over God enjoys the input of His people. God was amazed when David wanted to build a house for Him, without Him asking. We are able to bless the Lord by our response to Him. You have a box that needs to be filled but you are part of the filling. If you're still in doubt Jesus told His disciples, "I no longer call you servants...but I have called you friends." John 15:15 Be a friend of God, pour your input into your box with God and watch what happens.

Thursday, November 22, 2012

The Real Parallel Universe

Science fiction loves to tell stories of parallel universes, invisible worlds as close as our breath but unknown to men where every now and then a soul slips in and a wonderful adventure begins. This delightful topic of fiction is in fact reality; we live in a parallel universe where our natural world is mixed with an invisible one. The Bible tells us that we live in both a natural and a spiritual world and we can interact with both.

I believe that everyone is created to interact with this invisible realm but many have never had their eyes opened or don't take the time to become familiar with it. So the common condition is to be directed by the dictates of this natural world. God does not call us to such a one sided existence; not only does He call us into His unseen realm, He Himself gives us abilities to interact with it, beginning with the simplicity of a bended knee in prayer.

The Bible tells us about the spiritual gifts God has for us. God gives them to us as we ask but He also gives them as He wills and we might experience them without asking or fully understanding their nature or purpose. I wonder if you know what it is to see someone across a room and immediately feel their pain in your body or a burden of their heart press upon yours; to discern someone who has an hidden motive in a business transaction or to know what God is about to do in someone's life. These are expressions of those gifts. What about praying for an physical injury and seeing it immediately disappear, knowing a stranger's thoughts, seeing angels and demons or having faith to believe for impossible situations? These are some of the amazing spiritual gifts God gives us.

For many years I experienced and loved these gifts but didn't really understand the details. I was both keenly aware of Heaven's activity yet ignorant of how to interact with it. In some respect it's like being an X-Man having supernatural abilities that make me different in a good way. I talk to people about these things but it seems to be a language not everyone understands.

Now I've come to Bethel in Redding, CA, where I'm surrounded by 2,000 students who totally understand this realm. They live, eat and breathe this invisible reality. It's like coming to a school for the gifted, where once you thought you were unusual but now you realize you're normal. Even after months here the reality of this can be overwhelming. Yesterday was such a day, that day I saw the Holy Spirit guiding and leading me with more clarity and precision than I've ever known. In the last session I'm sitting at a table with students I've just met and hear one say "I'm such a feeler" and I know EXACTLY what she means. She's an X-Woman, a student with supernatural abilities, able to feel people's pain, joy, grief and longings; she knows where God stations His angels in a room and how He's feeling about someone or something. As she speaks it seems like decades of hidden understanding overwhelm me as she articulates her invisible gift.

This is Bethel, the most exciting environment for discovering God. I've heard teaching about the gifts and their operation, now I have an entire leadership team demonstrating, cultivating and awakening those gifts. Imagine what it's like to suddenly realize God has made you a seer and He speaks to you in images, or that you're a feeler and you feel things, a gift that can be so strong that some here thought they were bi-polar because of the emotional swing caused by encountering different people. As Kris Vallotton said in class, "Many of you were the most spiritual people in your church and your leaders weren't sure what to do with you. Welcome to the land of the giants!" Oh how I love this new world! If this resonates in your heart, run for the things of God. Ask Him, ask Him, ask Him questions. Seek and you will find.

Wednesday, September 1, 2010

DP_DefaultValueTypeDoesNotMatchPropertyType Error

If you create a Silverlight (and probably WPF) usercontrol and get a DP_DefaultValueTypeDoesNotMatchPropertyType error when rendering the control, make sure you are setting the right kind of default value in the .Register method.

The following code generated that error.

public static readonly DependencyProperty HourFillProperty = DependencyProperty.Register(
"HourFill", typeof(int), typeof(ucScheduleHour),
new PropertyMetadata(null,
new PropertyChangedCallback(ChangeValue)));


My value was an int so I needed to change null to a 0,


public static readonly DependencyProperty HourFillProperty = DependencyProperty.Register(
"HourFill", typeof(int), typeof(ucScheduleHour),
new PropertyMetadata(0,
new PropertyChangedCallback(ChangeValue)));

Wednesday, March 31, 2010

SQL WHERE and JOIN clauses

A brief discussion of the difference in SQL between criteria in the WHERE and JOIN clauses.

Suppose we have a very simple system of two tables A & B. A is a list of Deptartments and B is a list of charges to a departmental account.

Table A
Dept
10
20
30

Table B
Dept Acct Amt
10    15    2
10    11    4
20    11    1

Management request a report that shows all Depts in table A, regardless of the entries shown in B, and the sum of Amount by Acct for dept 15.

You might be tempted to write the SQL as:

SELECT A.DEPT, B.ACCT, SUM(Amount) as TOTAL
FROM A LEFT OUTER JOIN B
ON A.DEPT=B.DEPT
WHERE ACCT = 15 OR ACCT IS NULL
GROUP BY A.DEPT, B.ACCT

However this will give you these results.

Dept Acct Amount
10    15    2
30    NULL  NULL

Dept 20 does not appear in the list. As you can guess from the sample data Dept 20 is eliminated by the where clause, although the
DEPT IS NULL allows Dept 30 to appear.

There is a simple fix to show all departments, move the criteria to the JOIN.

SELECT A.DEPT, B.ACCT, SUM(Amount) as TOTAL
FROM A LEFT OUTER JOIN B
ON A.DEPT=B.DEPT AND ACCT = 15
GROUP BY A.DEPT, B.ACCT

This yeilds

Dept Acct Amount
10    15    6
20    NULL  NULL
30    NULL  NULL

Exactly what was requested.

Here is a little SQL which demonstrates the results.

SELECT A.DEPT, B.ACCT, SUM(AMT) AS AMOUNT
FROM
(SELECT 10 AS DEPT
UNION
SELECT 20
UNION
SELECT 30 ) A
LEFT OUTER JOIN
(
SELECT 10 AS DEPT, 15 AS ACCT, 2 AS AMT
UNION
SELECT 10, 11 , 4
UNION
SELECT 20, 11 , 1
) B
ON A.DEPT=B.DEPT AND B.ACCT=15
--WHERE B.ACCT=15 OR B.ACCT IS NULL
GROUP BY A.DEPT, B.ACCT

Friday, October 30, 2009

Reconnect SQL user after restore

Have you ever restored a SQL database with a SQL login to a new server and not been able to use the SQL login. So you log into Management Console to create the login, which you can but when you try to give it rights to the database, it says "User, group, or role already exists in the current database."

There is a simple way to fix this. Create user in SQL, connect as sa or admin, select the database you just restored and execute

exec sp_change_users_login 'Auto_Fix', 'yourUserName'

You should see a message like.

The row for user 'yourUserAcct' will be fixed by updating its login link to a login already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.

Tuesday, October 6, 2009

Correct way to Load a window in WPF

Here is the correct way to load a window in WPF. Notice the hooking the Loaded event in the constructor.

public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Window_Loaded);
//MyBigRoutine(); -- Don't do this.
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
MyBigRoutine();
}

Call to MessageBox.Show in App() prevents StartupURI

Not sure what is going on here but a MessageBox.Show in the ctor of WPF's app.xaml.cs prevents the call to the startupURI object. Removed the call to Show and all is well.

Monday, August 31, 2009

Fixed C000021a BSOD

I am sure there are a myriad of reasons for the deadly C000021a BSOD. In my case I had installed the Exchange management tools in an attempt to update Active Directory Exchange information on my local machine. The install failed and when I rebooted a day or two later it blue screened. When I went to uninstall a KB patch to see if that would fix it, I saw Exchange was running on my machine. I left the patch installed, removed the partial installation and the BSOD was banished.

As always when something crashes ask yourself, "What changed." Answering that question is the shortest route to fixing confusing problems.