T-SQL: setting decimal value always rounds up or down

Forgive my brevity on this post but I am writing to you today from my cell phone.

You may run into the problem I just had and I wanted to let you know what the issue was and how I solved it.

Suppose you have the following code:

DECLARE @decimalValue1 decimal = 5
DECLARE @decimalValue2 decimal = 10
DECLARE @resultValue decimal
SET @resultVaule = @decimalValue1 / @decimalValue2
PRINT @resultValue

You would expect to get a value of .5 but in fact the value is always 1. The problem here is that we did not specify the precision of the decimal data types.

DECLARE @decimalValue1 decimal(18,2) = 5
DECLARE @decimalValue2 decimal(18,2) = 10
DECLARE @resultValue decimal(18,2)

Now when the code is executed the correct decimal value will be displayed.

Tags: ,
Posted in Programming Snippets by RobK410. No Comments

Microsoft Releases Roslyn Project, Open Compiler API

This is amazing. Microsoft has made the inner workings of their IL compiler open to everyone by exposing the inner workings through an API. As the Overview describes, they’ve rewritten the IL compiler in managed code and in doing so have un-boxed the black box that was once the best IL compiler for Windows. It will be amazing to see how exposing this API will provide new development tools for increasing code-completion/style/correctness.

Traditionally, compilers are black boxes – source code goes in one end and object files or assemblies come out the other end. The Roslyn project changes that model by opening up the Visual Basic and C# compilers as APIs. These APIs allow tools and end-users to share in the wealth of information the compilers have about code. The Roslyn CTP previews the next generation of language object models for code generation, analysis, and refactoring, and the upcoming support for scripting and interactive use of VB and C#.

Original Source: MSDN Roslyn

Tags: , , , ,
Posted in Geektopia Programming by RobK410. 1 Comment

How to alter table column to increase varchar size

The top results in a general search through Google for keywords in the title of this post will return results which will not work with SQL server. Some suggest using the ALTER tablename MODIFY column syntax for which SQL Server does not support MODIFY. In order to change the size of a varchar column (or make many other changes to a column in SQL Server)  one utilizes the ALTER [tablename] ALTER [columnname] syntax.

So for the table:

TABLE  [Users] (
    [userID] int identity,
    [State] varchar(2),
    ....)

to change the size of column [State] from 2 characters max to 30 characters we use the following SQL:

ALTER TABLE ide_Users ALTER COLUMN [State] varchar(30)
GO

That’s it!

My feelings attempting to build a Linux package

Tags: ,
Posted in Ponderings The Bit Bucket by RobK410. No Comments

myIP: A robust command line tool for retrieving local and remote IP addresses

In usual fashion I sat down the other day and tried to come up with a useful tool I could quickly code. After about a week of coding and testing I’ve come up with a simple command line tool that will retrieve and display both v4 and v6 IP address information for one or more network adapters enabled within a computer. Written in C#, it utilizes the NetworkInterface classes to retrieve information about your computer’s network configuration. It also will ping a remote web service I created to retrieve your outward facing IP address if you’re on a proxy network. It doesn’t stop there however. You can also export your adapter information to both XML and the Windows clipboard. A simple icon can be configured on your desktop to allow a quick copy of your internal or external IP address information to the clipboard with just a double click. For example, using the command “myip -a 0 -eo -c” will get the external IP address for your first network adapter and copy it to the clipboard. Hope you all enjoy and be sure to write back some comments if you find the code and software useful.

Retrieving the external network ip address

Windows Installer (Requires .NET 3.5 Runtime): myip.1.0.final.windows.zip

C# Source Code (Requires CmdParamLib library): myip.1.0.final.sourcecode.zip

UPDATE: I’ve compiled and added a Linux based version of the tool for those who wish to use the program on their Linux machines. Compiled for Debian let me know what versions of Linux this does and does not work with!

Linux Package: myip.1.0-final-linux.tar.gz