DECLARE @LastmonLastBusinessDay date, @inputdate date
SET @inputdate = ’05/25/2014′
SELECT @LastmonLastBusinessDay = DATEADD(ms,-3,DATEADD(mm,DATEDIFF(mm,0,@inputdate),0))
– CASE DATENAME(dw,DATEADD(ms,-3,DATEADD(mm,DATEDIFF(mm,0,@inputdate),0)))
WHEN ‘SUNDAY’ THEN 2
WHEN ‘SATURDAY’ THEN 1
Recently I have been noticing some weird special characters on my PuTTy screen. There was no pattern to it. It will appear all of a sudden.
Its so annoying when you are working on a script.
Reason : To keep my windows active from locking, I had installed an application called ‘caffeine’ . Caffeine periodically sends a key stroke to my session active. Whenever caffeine sends a keystroke and if my PuTTy is active it a special weird character gets displayed on screen.
Solution : Set the status of Caffeine to InActive when using PuTTy and it solves the problem.
Here is a simple command line statement to kill frozen windows task manager.
START – RUN – CMD (make sure you are running it as Administrator)
C:>taskkill /F /FI “WindowTitle eq Windows*”
Taskkill – Command
/F – Forcefully terminate the process(es)
/FI – Filter
“WindowsTitle” – valid filter
eq – valid operator
C:> taskkill /? to learn about more valid filters and valid operators regarding taskkill command.
Happy Scripting !!
Its easy to convert DVD folders to ISO.
Mac offers hdiutil command line tool which can be used for to achieve the same.
Open Terminal Window (GO > Utilities > Terminal)
Type the following command
$ hdiutil makehybrid -udf -udf-volume-name <<YourDVDVolumeName>> \
-o <<yourname.iso>> /folderpath/parentdirectoryofvideo_ts
Note: If video_ts resides on /user/user1/download/movie1/video_ts
above command will look like
$ hdiutil makehybrid -udf -udf-volume-name movie1 \
-o movie1.iso /user/user1/download/movie1
In few minutes .iso file will be ready.
By default the output iso file will be stored on /user/user1 folder.
Deleting duplicate rows in SQLServer is very simple.
Example : Check this table let me call it as Sample, order number 1,2 & 3 have identical values. Now we need to delete the duplicate rows.
Step 1 : Insert another column in table Sample called Dup of type Integer.
Step 2 : Execute this Query (uses Common Table Expression)
WITH DUP_CTE AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY ORDERNO,Name,COST ORDER BY ORDERNO) AS DupRank FROM Sample
UPDATE DUP_CTE SET Dup = DupRank
Now the table looks like this
Step 3 : Delete all the rows where Dup greater than 1
DELETE Sample Where Dup > 1
Step 4 : If new column Dup is not needed drop it from Table.
Easy right !!
When you try to run/execute a .vbs file, you will be prompted with Security Warning. The security warning is good and it saves your PC from some malicious programs. But its an annoyance when you try to execute your own code.
As VBScript developer you will face this issue a lot when try to Schedule your task. To overcome this Microsoft suggest to set the Environment variable called SEE_MASK_NOZONECHECKS to 1.
set oShell= CreateObject("Wscript.Shell")
set oEnv = oShell.Environment("PROCESS")
oEnv("SEE_MASK_NOZONECHECKS") = 1
oShell.Run "c:\projects\sample.vbs /norestart",0,True
Recently tested this code on Windows 7 64 bit and it worked fine.