THOUGHT VS WISH

I was brainstorming about several things and hit on the question. What is the difference between thought and wish ?

and it appears that though both seem similar, their true meanings are miles apart !!!

simply put you can define the relationship between them as:

ALL WISHES ARE THOUGHTS, BUT ALL THOUGHTS ARE NOT WISHES.

you can think of anything but it does not mean that you wish for that !!!!

 

Cheers 

Balachandra

Advertisements

Sequencial convoy scenarios

Tags

Hi,

Just now I developed few samples for various sequential scenarios in the lines of same and different message types, same/different ports, same/different operations. There is one important point to remember is that, while developing sequential convoy with different ports for receiving, you will run into a compile time error “in a sequential convoy the ports must be identical”. This means that there is no send shape between any 2 consecutive receive shape that are bound to different ports and NOT the same port.

To avoid this use send shape in between sequential convoy receive shapes (like below).

Image

 

The sample code for these scenarios are uploaded in here. try them out

Cheers

Balachandra

Sql Server Having and Where clause

Tags

Hi all,

I faced a scenario where I had to write group by queries to get aggregate information. It was long time since I was deeply involved in Sql.

Here is the scenario :

3 tables, Member, Book and Rentals. Members of the library are allowed to rent multiple copies of books several times. basically it was a many-to-many mapping between Member and Books through Rentals

Img1

Data to be queried: Retrieve all book names and the total qty of each book rented out by a member, lets say ‘Claire’

There are 2 ways to do it:

1. you can join all the 3 tables and then group by members and books and then filter the grouped records for the member ‘Claire’

select B.Name, Sum(R.CopiesRented)
from
Member M inner join Rentals R
on (M.Id = R.MemberId)
Inner join Book B
on (B.Id = R.BookId)
Group by M.Name, B.Name
having M.Name = ‘Claire’

Or

2.  you can join all the 3 tables and then filter the records for the member ‘Claire’ and then group by books.

select B.Name, Sum(R.CopiesRented)
from
Member M inner join Rentals R
on (M.Id = R.MemberId)
Inner join Book B
on (B.Id = R.BookId)
where M.Name = ‘Claire’
Group by B.Name

The 2nd query is better in terms of performance as it first filters out the unwanted records using the “Where” condition and then groups the remaining records. However the first runs the burden of Grouping all the records and then applies the having filter.

It is good to always filter out as many records as possible before the execution moving to next operation (“grouping” in this case)

Group By is costly operation because it has to do the sorting operation for all the qualified records and then perform grouping.

Similarly another scenario:

Query to retrieve total number of copies of a book rented by every member. Lets say Book = ‘Sql Server Unleashed’

1.
select M.Name, sum(R.CopiesRented)
from Member M inner join Rentals R
on (M.Id = R.MemberId)
inner join Book B
on (R.BookId = B.Id)
where B.Name = ‘Book1’
Group by M.Name

2. select M.Name, sum(R.CopiesRented)
from Member M inner join Rentals R
on (M.Id = R.MemberId)
inner join Book B
on (R.BookId = B.Id)
Group by B.Name, M.Name
having B.Name = ‘Book1’

(1) performs better than (2) because of using the where clause.

Cheers

Balachandra