Thursday, September 8, 2011

Check MD5 or SHA1 hashes in Windows

If you ever download stuff off of web, you should use some sort of checksum tool.  I believe in most Unix/Linux flavors of Operating Systems, come with a checksum tool, but no such luck in Windows.

Have you every wished every edition of Windows came with checksum tool?  Well, almost.  As far as know, most of the Windows versions do not come with this tool, however, Microsoft does provide one.  In the past, I have used to use various other third party tools whichever I could find online at that instance, but I would rather use one that is provided by Microsoft itself.

So, just go to this page and install it:
http://www.microsoft.com/download/en/details.aspx?id=11533

As the page states, this small command line tool works on Windows 2000 or higher.

Hope you find this useful.

Thanks.

Sonny

Monday, March 21, 2011

Can’t Use Inline Function Calls While Calling a Stored Procedure

I can’t believe it has been more than 18months since I have written a blog.
Today, I was trying to call a stored procedure in SQL Server 2008 and keep getting Incorrect syntax error.
For example, let’s say, I have a following stored procedure on the asp.net membership provider that returns active users since a given date:
CREATE PROCEDURE _GetActiveUserSinceDate
@SinceDate DATETIME
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM [dbo].[aspnet_Users]
WHERE [LastActivityDate] >= @SinceDate
END
And when, I try to call this stored procedure as follows to get me the list of users logged in the last 7 days:
EXEC [dbo].[_GetActiveUserSinceDate] DATEADD(d, -7, GETDATE())
I would get the following error message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'd'.
I was able to get around this error message by explicitly assigning the return value of DATEADD function to a variable and passing that variable to my stored procedure as shown below:
DECLARE @SinceDate DATETIME
SET @SinceDate = DATEADD(d, -7, GETDATE())
EXEC [dbo].[_GetActiveUserSinceDate] @SinceDate
I keep thinking of why do I need to have this extra variable and why can’t use the function inline and so searched on MSDN and found the following page:
Look under the “Specifying Parameters” section and you see the following statement:
The supplied value must be a constant or a variable; you cannot specify a function name as a parameter value. Variables can be user-defined or system variables such as @@spid.
So there you have it and it is my bad to use the same mindset while writing TSQL as I do while writing C# code. If you already know about this, you are a lot a better TSQL programmer than me.
Thanks for reading.
Sonny

Tuesday, August 11, 2009

24 Hours of Nonstop SQL Server Training

Get ready for brain overload, 24 hours of nonstop SQL Server training by experts all around the world! And best of all it is FREE and you don't have to go anywhere to get this training. Here is the link to this training http://24hours.sqlpass.org.

Anyway the reason for my post is not to propagate about this event, though it is not a bad idea, but to share a little javascript. When I went to register for sessions, all the start times are listed in GMT and I wanted to be able to see the times in local timezone format. Here is a sample screenshot of how the start times are listed:



If you are using IE8, it is really easy to run custom javascript code on any page, you simply press F12 and go to the Script tab in the Developer Tools window and then run the following javascript code:


var sp = document.getElementById("schMeetings");
var timeSpans = sp.getElementsByTagName("span");
for (var i = 0; i < timeSpans.length; ++i)
{
if (timeSpans[i].id.indexOf("lblScheduletime") > 0)
{
var dtStr = timeSpans[i].innerText;
var dt = new Date(dtStr.substr(0, dtStr.length-"+00:00".length));
timeSpans[i].innerHTML += " [" + dt.toLocaleString() + "]";
}
}


Once I ran this javascript snippet, I can see the start times in my local timezone format as shown below:



I really like the new IE8 Developer Tools and this is just a sample of what you can do with custom javascript on any web page you visit.

Happy Coding,

Sonny