Saturday, May 9, 2015

Using Case Statement in Where clause

Recently I faced a situation where I need to decide by where clause value based on certain condition

so situation was some thing like this: To select some records for a userid and if userid passed is 0 then also we need to get records so my query was something like this:

select * from [user]
Where userId = @userId

Not if @userId is passed as 0 still I want the above query to get executed one way was to put if condition like

if @userId > 0 then
BEGIN
                 select * from [user]
END
ELSE
                  select * from [user]
                 Where userId = @userId

But I found a more smarter way ( which I think it is)

select * from [user]
Where userId = ( Case When @userId != 0 Then
                                         @userId
                              Else
                                        userId
                              End)

:) isnt't it cool :)





Wednesday, May 6, 2015

Javascript's indexOF is case oriented

Our own little javascript's little cute indexOf function is case sensitive and I am surprised why???

so var s = 'hello world';

s.indexOf('hello') returns 1 and s.indexOf('HELLO') returns -1

Aaaarrrrrrrggggggghhhhh...... Lets enjoy this :)





Solution I forgot (Bad habit to rush to you tube for new songs hehe he he.....)

 s..toLowerCase().indexOf('HELLO') is good to go   ;)


Saturday, May 2, 2015

MSDn sayings :)


  • The operations are primarily CPU operations instead of operations that involve extensive disk or network overhead. Using asynchronous action methods on CPU-bound operations provides no benefits and results in more overhead.
This means that async action methods should not be used in the above scenario means CPU bound operations are those which just need CPU power for example a long runing loop doing lots of calculations.

Async action methods to be used only which are disk or network overhead which are those??? Those are result of big query which involves reading to or writing to disk.