Multiple aggregate clauses in a group by..
select mstr_date
,sum((case when bs ='S' then -1 else 1 end )*quantity) as qty_sum
,sum((case when bs ='S' then -1 else 1 end)*orig_face) as orig_face_sum
,count(*)
from table_name
where column='xxxx'
group by mstr_date
order by mstr_date
I never tried this until now. Very interesting.
Thursday, December 23, 2010
Thursday, December 2, 2010
Closing a Swing Application
Just calling toplevel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); is not good enough.
There could be other frames still alive, esp if you are using a third party library.
So your JVM is still running. Here is how you fix it..
Get all the frames that are currently running and dispose each of them
Frame[] frames = toplevel.getFrames();
for(int i=0;i
Frame frame = frames[i];
frame.dispose();
}
-Sonu
There could be other frames still alive, esp if you are using a third party library.
So your JVM is still running. Here is how you fix it..
Get all the frames that are currently running and dispose each of them
Frame[] frames = toplevel.getFrames();
for(int i=0;i
Frame frame = frames[i];
frame.dispose();
}
-Sonu
Wednesday, October 20, 2010
Excel logical if
Compare two columns and find out whats different.
Lets say you would like to compare col A1 and F1. Here is the logical if condition in excel you would use...
=IF(A1=F1,"","***")
The column would print *** when the values in A1 and F1 are different.
-Sunny
Lets say you would like to compare col A1 and F1. Here is the logical if condition in excel you would use...
=IF(A1=F1,"","***")
The column would print *** when the values in A1 and F1 are different.
-Sunny
Thursday, September 9, 2010
useful cvs commands
If you made local changes and if you like to diff the latest version in repository,
cvs -Q diff -c StormAccrual.pl
cvs -Q diff -c StormAccrual.pl
Tuesday, August 10, 2010
Unix file processing
This command is very useful to analyze data files
cut -d ' -f |
single col :
cut -d '|' -f1 uncl_sims_audit_clr_code_null.txt | sort|uniq
multiple cols
cut -d '|' -f1-2 uncl_sims_audit_clr_code_null.txt | sort|uniq
enjoy..!
cut -d '
single col :
cut -d '|' -f1 uncl_sims_audit_clr_code_null.txt | sort|uniq
multiple cols
cut -d '|' -f1-2 uncl_sims_audit_clr_code_null.txt | sort|uniq
enjoy..!
Wednesday, July 7, 2010
Passing arrays to perl subroutines
Finally when we receive thes values in@_ variable then we can not recognize if we had passed one array or two value arraysbecause finally it is getting merged into one.
o
If you want to work with and identify the individual lists passed to Perl, then you need to use references:
(@listc, @listd) = simplesort(\@lista, \@listb);
The leading \ character tells Perl to supply a reference, or pointer, to the array. A reference is actually just a scalar, so we can identify each list by assigning the reference to each array within our subroutine. Now you can write your subroutineas follows:
sub simplesort
{
my ($listaref, $listbref ) = @_;
# De-reference the array list
my (@lista) = @$listaref;
my (@listb) = @$listbref;
# Now you can play with both arrays.
}
o
If you want to work with and identify the individual lists passed to Perl, then you need to use references:
(@listc, @listd) = simplesort(\@lista, \@listb);
The leading \ character tells Perl to supply a reference, or pointer, to the array. A reference is actually just a scalar, so we can identify each list by assigning the reference to each array within our subroutine. Now you can write your subroutineas follows:
sub simplesort
{
my ($listaref, $listbref ) = @_;
# De-reference the array list
my (@lista) = @$listaref;
my (@listb) = @$listbref;
# Now you can play with both arrays.
}
Wednesday, June 23, 2010
Syntax of inner join
select * from foo
inner join (
select 5 as bar
union all select 6
union all select 7
) as x on foo.bar = x.bar
inner join (
select 5 as bar
union all select 6
union all select 7
) as x on foo.bar = x.bar
Thursday, March 18, 2010
Change End of Line characters in eclipse
Remove Ctrl M characters in vi
To remove windows end of line characters, Ctrl M characters in vi
1) open the file in vi
vi
2) Type the following
To get ^M, press ctrl key on your keyboard and press v and m
:%s/^M//g
3) dont forget to save the file with :wq!
Enjoy.
1) open the file in vi
vi
2) Type the following
To get ^M, press ctrl key on your keyboard and press v and m
:%s/^M//g
3) dont forget to save the file with :wq!
Enjoy.
Monday, February 22, 2010
Forcing index- SQL
So if cust_num is the 6 th index created on the table. Here is how you force the index while querying the database table :
select * from tranhist (6) where cust_num='AA25150'
select * from tranhist (6) where cust_num='AA25150'
Thursday, February 18, 2010
Excel Printing header on each line
Goto File -> Page Setup -> goto sheet tab -> In Print Titles section, Rows to repeat at top, enter the range of rows you would like to repeat : $1:$1
http://www.mrexcel.com/tip129.shtml
http://www.mrexcel.com/tip129.shtml
Wednesday, February 3, 2010
SQL Not in vs Join example
Obviously SQL join is more efficient than the not in clause. Here is an example of both.
Most inefficient Not in query :
select count(*)
from
wire_instr w
where
w.short_code
not in (select short_code
from nostro_accts)
Slightly better Not Exists query :
select count(*) from
wire_instr w
where not exists(
select 1
from nostro_accts n where
n.short_code=w.short_code)
Finally the Join query :
Join infact creates a new table which
select w.short_code as wshort,n.short_code as nshort from wire_instr w
left outer join
nostro_accts n
on n.short_code=w.short_code
where n.short_code=null
Enjoy
-Sunny
Most inefficient Not in query :
select count(*)
from
wire_instr w
where
w.short_code
not in (select short_code
from nostro_accts)
Slightly better Not Exists query :
select count(*) from
wire_instr w
where not exists(
select 1
from nostro_accts n where
n.short_code=w.short_code)
Finally the Join query :
Join infact creates a new table which
select w.short_code as wshort,n.short_code as nshort from wire_instr w
left outer join
nostro_accts n
on n.short_code=w.short_code
where n.short_code=null
Enjoy
-Sunny
Friday, January 29, 2010
Replace with new line in eclipse
Eclipse VM Args
Multiple VM args can be entered to eclipse by separating them with a space. See the picture below :
2) Issue : Eclipse doesnot allow spaces in vm arguments.
You can force eclipse to take a space by wrapping the value of your argument in double quotes.
-Dpropsfile="H:/user data/eclipse/workspace/wires/etc/dev.config.props"
Cheers,
Sonu
2) Issue : Eclipse doesnot allow spaces in vm arguments.
You can force eclipse to take a space by wrapping the value of your argument in double quotes.
-Dpropsfile="H:/user data/eclipse/workspace/wires/etc/dev.config.props"
Cheers,
Sonu
Friday, January 15, 2010
Friday, January 8, 2010
Perl ternary operator
I was trying to use an if else stmt in perl inside a join. And it was throwing compilation errors. In this case you can use a ternary operator to serve as if else :
ex :
($Bond{$_}{CFAC} ==-1 ?”N/A” : $Bond{$_}{CFAC})
ex :
($Bond{$_}{CFAC} ==-1 ?”N/A” : $Bond{$_}{CFAC})
sybase convert float to char
Sybase function to convert float to char
convert(char(10),isnull(convert(char(18), pi.factor),'N/A')) as factor
convert(char(10),isnull(convert(char(18), pi.factor),'N/A')) as factor
Subscribe to:
Posts (Atom)