Get table of dates between two dates (period of dates) dynamically

Well I am kind of sure anyone dealing with database queries must have come across this problem

The problem

You need a list (or better said) table of Dates between two dates (start date, end date ) that you have

 

The solution

Well usually you will be handling this using loops, coursers to do your operation row by row for each date between start date and end date,

While playing around I just found another way(I feel it is better way)

The Better way

Just found out that TSQL (since SQL SERVER 2005) new keyword is introduced WITH and it is used to created temporary table !

So why don’t we create a temp table using WITH that has dates between my start date and end date

Here is how

declare @start datetime

,@end datetime

 

set @start=’6/20/2011′;

set @end=’7/19/2011′;

 

with alldates as


(


select @start DateVal


union
all


select DateVal + 1


from alldates


where DateVal + 1 <= @end


)

 


select DateVal


from alldates;

 

This will list down dates

Well doing that will gave me all dates within my start date and end date

 

BUT

but still there is some problems with the WITH keyword (it could be better in SQL SERVER 2008) in SQL SERVER 2005 you can’t use it in complicated query

 

CORRECTION

 

Simple enough what I did currently is I can get the start date and the end date from another table by sql query , so I created a view that that uses the mighty WITH and creates dynamic list of dates between two dates in different table (note: this code is written as if the T_Period table has only one row, in case there were more rows a where condition could have been added like where PeriodToUse=1
)

create
VIEW [dbo].[V_DATES_OF_PERIOD]

AS

 

WITH alldates AS
(SELECT period_start AS DateVal


FROM dbo.T_Period

 


UNION
ALL


SELECT alldates_2.DateVal + 1 AS Expr1


FROM alldates AS alldates_2


WHERE
(alldates_2.DateVal+ 1 <=
(select period_end from dbo.T_Period)

))


SELECT DateVal


FROM alldates AS alldates_1

GO

 

SET
ANSI_NULLS
OFF

GO

SET
QUOTED_IDENTIFIER
OFF

GO

Read More

Android iPhone Apps developers

Smart phone apps are the new hot thing in the horizon, all technology entrepreneur are thinking to move their business (partially , or clone) from web or desktop to smart phones. Well that not something no one was expecting but until iPhone come to the world people were thinking it will be on Nokia’s Symbian phones anyone remember (S60).

 

Well once iPhone came many developer looked at it as a big possibility, but there were limitations in the initial IOS version ,in wireless mobile data connections (no 3g or very expensive) , in development support (less APIs , limit programming in Objective C) , in features of hardware.

 

But in that time another giant was looking at it also as a big possibility, but why don’t we make the possibility in our own way, and why not make it bigger wider and better! , that giant was Google, and here was the birth of Android.

 

Having these two super powerful operating systems for smart phones(IOS & Android) now it is the time for innovation and there are lots of innovators creating great really great apps and games for these devices that will one day be with each and every human being .

 

As OmanDev.NET we decided two things

  1. As bloggers we will be addressing these innovators of new world and will be reviewing them and their apps & games
  2. As programmers we should start contributing to the world with our ideas our innovations (so wish us luck , or better lend us a helpful hand)

 

 

Read More

Google I/O Captions

In addition to the live streaming for Google I/O, Google (YouTube) start a live captions generated from the live streaming. It is really human like captioning.

You have to see it,
http://www.youtube.com/user/GoogleDevelopers

Read More

Google IO 2011 – Day 2

Is Google taking over the world or is Google taking over the world??

Google IO logo

so, they are taking over the Mobile Phones market, … they are headed for Home appliances (Android@Home) and now this ….

Google just announced “Chromebook” (http://www.google.com/chromebook/#features) a notebook that has a web-based OS, A.K.A “Chrome OS” …
Chromebook

Now, this is not the first time they talk about “Chrome OS” but this time they have team-ed up with hardware manufacturers (Samsung and Acer) to build a complete consumer product. and they will give every Google IO 2011 attendee a free Samsung Chrome-book! (Plus the Samsung Tab 2 gift that they announced yesterday) .. Man those guys are lucky

On another note, .. Google has just announced “Angry Birds” first truly web-based experience on Chrome (using nothing but JavaScript, HTML5 and of course the engines!) ..

Angry Birds

What are you waiting for? go get it and try it on your chrome! https://chrome.google.com/webstore/detail/aknpkdffaafgjchaibgeefbgmgeghloj?hl=en-US .. happy angry-bird-ing x)

Read More

Google I/O 2011

Google i/o 2011

What is up Google?

Google just announced some really interesting stuff at Google IO 2011, and no am not talking about HoneyComb 3.1 or the new Ice Cream Sandwich Logo!!

They announced Project “Android@Home” A.K.A “Skynet”!!! Lol I mean seriously!!! its about controlling your home using your phone.

switching your lights On / Off using your phone, opening the TV, activating the Washing Machine, .. i know that most of those things already exist separately, .. but doing it all using your android device … that is cool, but maaan i could think of many things go wrong x).

another thing announced is this “wireless protocol” i can see Bluetooth dying soon (anyone remembers InfraRed??)

and how the hell did they manage to transfer a whole music CD to a “white orb” wirelessly within 2 seconds!!! 2 SECONDS!!! just by waving a CD to a white orb! How did they do that?

Android@Home is the big thing, Google is going bigger than ever!

Read More

Google Code Jam 2011

First time for me at Google Code Jam.

The timing of the contest is awful for people in the middle east (the competition starts at 3:00am). and yes i know that it stays open for 24 hours, but you receive penalty for each one minute late you submit your answer! and its not the weekend for us (our weekend is Thursday + Friday not on Saturday + Sunday! ), AND most of us have jobs / courses to attend the next day, so yeah the time is awful!.

anyways, qualification questions this year was not really REALLY hard! i would assume many people would been able to solve at least 3 questions out of four given good practice and clear mind.

I had only about 2.5 hours to look at the questions and solve them, I concentrated on the first question (which had 20 points). which was obviously a bad decision from my side (i didnt pay attention to the qualification criteria), because the one needs at least 25 points to qualify, and this is the only question that had under 25 points!!!

Problem A (you can view the questions list from http://code.google.com/codejam/contest/) was entitled “Bot Trust” the moment i saw it i knew i JUST KNEW that there is a simple equation to get the result, i tried to figure out the equation but i just couldnt, so i took the long way, and I simulated the whole thing and submitted.

I had a chance to look at other question, i checked questions B and C, entitled “Magicka” and “Candy Splitting” respectively.

Magicka is easy if you use queues, you enqueue the invoking list, dequeue character by character and compare with the combination / clear list you have, the bad thing about this question (as i found out) was the hideous input splitting, there were so many different tokens in the input that it just gave me headache and i stopped half way through, i was able to generate a decent list of cases, but it was not entirely accurate, i didnt continue further, i left this problem because it gave me a massive headache.

Candy Splitting” … ohhh Candy Splitting, i should have started with this problem i would have been qualified by now, .. its nothing than a mere XOR operation, when i looked at it, it was very late and i barely had any energy but to regret on “WHY oh WHY didnt i start with this problem”.

i didnt read the last questions “GoroSort” .. funny name, though! lol

anyways, .. it was fun, couple of lessons learned

1. Look at (and understand) ALL the questions before you start solving any of them.
2. Pay attention to the points given to each question, dont spend time on solving questions that has lower value if you could spend the same time solving a higher value.
3. If you are working / studying on next Google Code Jam (and you want to solve many questions), would recommend you take the day off.
4. Prepare some code before the competition (file I/O, some useful algorithms, etc) they come in handy in the competition.

See you at Google Code Jam 2012

btw, you can view the solutions of other competitors (in case you are wondering how they solved a given problem) go here http://code.google.com/codejam/contest/scoreboard?c=975485 then check the “Solution Download” check box

Read More