Question: i use this script to compress all .txt and .cpi files into the backup folder in separated files with 7zip. After the files are zipped i delete the original files. However this script has a logical flaw. Lets say if the 7zip program fails to run, the files will also get deleted. How can i change the script so that it should not delete the files if they don't get zipped first. Also how can i change this script so it zips files that are older than 7 days? Thanks for your help.
@echo off  

setlocal 

```
set _source=C:\test7zip\bak    
set _dest=C:\test7zip\bak    
set _wrpath=C:\Program Files\7-Zip        
if NOT EXIST %_dest% md %_dest%    
for %%I in (%_source%\*.txt,%_source%\*.cpi) do "%_wrpath%\7z" a "%_dest%\%%~nI.7z" "%%I" & del "%%I"

```

pause

Answer: 
This is a partial solution to a partial question, but generally you would use:

`ORDER BY YEAR(TimeColumn), DATEPART(m, TimeColumn)`
Repeating what has already been said

```
SELECT '01 jan 2012' AS Dt INTO #tempDates
UNION
SELECT '01 jun 2012'
UNION
SELECT '10 oct 2012'
UNION
SELECT '01 jan 2013'

--1
SELECT Dt
FROM #tempDates
ORDER BY DatePart(YY,Dt),DatePart(m,Dt)

--2
SELECT Dt
FROM #tempDates
ORDER BY YEAR(Dt), MONTH(Dt)

--3
SELECT Dt
FROM #tempDates
ORDER BY YEAR(Dt), DatePart(m,Dt)

```