Sunday, April 1, 2012

JD Edwards Dates in SQL Server

Recently I worked on a project where we had integration with JD Edwards.  In this project I got introduced to JD Edwards dates and times.  They are not stored as normal dates in .Net or SQL server.  But are numeric fields.

I needed to do a date comparison against a SQL Server date and a JDE date time.  To do this I created a user defined function.  This function converted the date and time fields in JDE to a SQL date I could use for comparison.

Below is the format of date and time fields in JDE.

Date Fields
The date fields are stored as six digit numbers with the format
CYYDDD
Where C = century after 1900.  So for the current century it would be 1, 1900 - 2000 = 1
YY is the year in the century for example 12 for 2012
DDD is the day of  the year.  For example April 1, 2012 is the 92nd day of 2012

Time Fields
Date and time fields are stored in separate columns in the JD Edwards database.
Time fields are stored in military time as
HHMMSS

HH = hour 1-24 not zero filled, so if its just after midnight you would have only MMSS
MM = minute 00-60 zero filled
SS = second 00-60 zero filled

Below is the user defined function I used to parse the date time.  The performance on this was not super great so to help it I put a Common Table Expression (CTE) in my stored proc.  This limited down the result set to speed up the conversion on a smaller number of records.

The performance seemed really bad when comparing SQL server datetime to the UDF result. Probably because it had to convert all JDE date times into SQL server datetime before it could do its comparison.

The UDF


  1. CREATE FUNCTION [dbo].[ToGregorian](@julian varchar(6),@time varchar(6))
  2. RETURNS datetime AS BEGIN
  3.     DECLARE @datetime datetime,@hour int, @minute int, @second int
  4.    
  5.     IF(LEN(@time) = 6)
  6.         BEGIN
  7.             SET @hour = Convert(int,LEFT(@time,2));
  8.             SET @minute = CONVERT(int,Substring(@time,3,2));
  9.             SET @second = CONVERT(int,Substring(@time,5,2));
  10.         END
  11.     else IF(LEN(@time) = 5)
  12.         BEGIN
  13.             SET @hour = Convert(int,LEFT(@time,1));
  14.             SET @minute = CONVERT(int,Substring(@time,2,2));
  15.             SET @second = CONVERT(int,Substring(@time,4,2));
  16.         END
  17.     else
  18.         BEGIN
  19.             SET @hour = 0;
  20.             SET @minute = CONVERT(int,LEFT(@time,2));
  21.             SET @second = CONVERT(int,Substring(@time,2,2));
  22.         END
  23.    
  24.     SET @datetime = DATEADD(YEAR,100*CONVERT(INT, LEFT(@julian,1))+10*CONVERT(INT, SUBSTRING(@julian, 2,1))+CONVERT(INT, SUBSTRING(@julian,3,1)),0);                     
  25.     SET @datetime = DATEADD(DAY, CONVERT(INT,SUBSTRING(@julian, 4, 3))-1,@datetime);                   
  26.     SET @datetime = DATEADD(hour,@hour,@datetime)
  27.     SET @datetime = DATEADD(minute,@minute,@datetime);
  28.     SET @datetime = DATEADD(second,@second,@datetime);
  29.    
  30.     RETURN @datetime
  31. END

Wednesday, March 14, 2012

Stuck in zoom mode

In visual studio sometimes my mouse wheel gets stuck in zoom mode.  To fix this in the past I have shut down visual studio.  Depending on the size of your project this can take some time.

I found a simpler solution.  clrl+a to select all and the mouse wheel zoom scroll is broken no longer.


Thursday, March 8, 2012

Command Window in Visual Studio

Tired of scrolling through your solution explorer looking for that class. You know the name of it, but you making that mouse wheel work overtime to find the class in your project.

To get around this just use your Command window in visual studio.  To open the command window
1. click on the view menu on the menu at the top of visual studio, or better yet, just 
2. Go to the other windows 
3. select command window
or shortcut keys ctrl+alt+a

this will open the command window docked at the bottom of visual studio.

Inside the command window you can just type "of" and part of the file name.  The command window will give you suggestions and you can pick the class file you want.


This has been a huge time saver for me.  Try it out.


Wednesday, March 7, 2012

#region #endregion - You might have stinky code

Methods perform one and only one function. Methods with less than 15 lines of code makes me want to take a deep inhale. Getting a good whiff of that fresh smelling code.

Having more than 15 lines of code most likely mean you are doing more than one function. When I see these types of methods, I want to hide my nose under my t-shirt. Or maybe just pinch my nose closed.  Writing unit tests for run on methods that reach 100's of lines is nearly impossible. The maintainability of long stinky methods is low. Of course there are always exceptions, but short  methods are always my goal.

If your method has regions, you might have stinky code.

Applying the same idea to classes works also.  I really don't have a target for a class.  No magic number of methods or number of lines of code in a class. Your code is most likely stinky if you have one class in your library or application that has hundreds of methods and over 50 percent of code in your application.  Even more likely if the class is called main, or util.

Again in a class if you might have stinky code if you have regions.

Leaving #region out of your code leads to fresh smelling code.

No regions also means you don't have to remember those pesky shortcut keys to expand those regions any more.


Tuesday, March 6, 2012

Keyboard and mouse

As a software developer one of my most important tools is my keyboard and mouse.  It is my connection to my computer.  Most times I am thinking about what I am doing so much the keyboard is an extension of myself.  I don't really think about what I am typing, I just think about it and it goes into the computer.  The typing is nearly subconscious.

However, if you have a poor mouse or keyboard, then this subconscious work of typing the keys becomes more of a conscious decision.  You have to think about where the keys are you need to press.

Ok, so I think a lot about the keyboard and mouse that I use. I have had many over the years, and my favorite right now is the Logitech wireless wave keyboard.  The keyboard feels very natural.  I don't have to think about typing i just think and type. I really like the small receiver, not like some of the old wireless stuff I have that has long cords.  The built in wrist wrest is stylish and looks very modern. The USB receiver is super small and you don't even notice it.   The combo has many other features I am sure are nice, but I really don't use them.

I have one both at home and at the office. I have found various deals on the combo but you are most likely going to pay around $60 dollars for it.  For me who uses a keyboard for many hours each day it is certainly justifiable.



Here is a link to it on amazon.
http://www.amazon.com/Logitech-Wireless-Combo-Keyboard-920-002555/dp/B003VAHYNC/ref=sr_1_1?ie=UTF8&qid=1331091048&sr=8-1

Monday, February 27, 2012

Automated TFS Testing

TFS is a great tool for doing automated testing. Last year I did a presentation and the twin cities code camp on automated testing using TFS. 

Using automated testing you can take a task that would take a QA analyst days to complete in just a few minutes. 

In this demo I show how to create an web performance test and also how to create your own web test plugins to extend the functionality that Microsoft gives you out of the box.


Friday, February 24, 2012

Visual Studio Themes

I spend up to 40 hours per week staring at visual studio. Visual studio is the best IDE for development in the industry.  However, there is always room for improvement.  And I am always looking for ways to be that lazy coder and make things easier and faster.  

One simple tool I use to accomplish this is to change my visual studio themes.  Its really easy to change and saves eye strain, and just is a way to personalize my Visual Studio experience.  

Of course you can always create your own themes, but being lazy I would rather have some one else create them for me.  And of course I don't really want to pay for them either.  Luckily someone has put together an cool site where users can upload and share there visual studio themes.  

When you download your themes you can make your life easy by putting them in the folder
C:\Users\[your user name goes here]\Documents\Visual Studio 2010\Settings

The site is simple, and easy to find your favorite Visual Studio theme.  I personal favorite is humane studio.  http://studiostyl.es/schemes/humane-studio


To install your downloaded theme in visual studio 
1. From the tools menu in visual studio select import and export settings
2. Import selected environment settings
3. Click next

4. you can choose to backup settings here, I usually don't


5. Click on browse to choose your settings

 6. pick your downloaded theme

7. Finish and your visual studio experience is customized.