|
|
-
|
|
To add or subtract days from a date, you can simply use:
-- © 2011 – Vishal (http://SqlAndMe.com)
SELECT GETDATE() AS 'Today',
GETDATE() + 10 AS '10 Days Later',
GETDATE() - 10 AS '10 Days Earlier'
Result Set:
Today 10 Days Later ......
|
|
-
|
|
You can do this using two different ways. First is to us DAY(), MONTH() an YEAR() TSQL functions. These functions return an integer representing a day/month or year respectively.
These can be used as:
-- © 2011 – Vishal (http://SqlAndMe.com)
SELECT DAY ( GETDATE() ) AS 'Day',
......
|
|
-
|
|
Following queries can be used to get First Monday of a week/month:
-- © 2011 – Vishal (http://SqlAndMe.com)
-- Monday of Current Week
SELECT DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0),
'Monday of Current Week'
UNION ALL
-- First Monday of the Month:
SELECT ......
|
|
-
|
|
Yesterday, I posted bout How to get the First and Last day of a Month. Same can be modified to calculate first/last day of a given year:
– © 2011 – Vishal (http://SqlAndMe.com)
– First/Last Day of the Year:
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0,
DATEADD......
|
|
-
|
|
Following queries can be used to get the first/last days of a month.
To get first day of a month use:
-- © 2011 – Vishal (http://SqlAndMe.com)
-- First Day Previous/Current/Next Months
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0),
'First Day of Prev......
|
|
-
|
|
xp_fixeddrives is a useful extended stored procedure which returns amount of free space available in MB, for all local hard drives.
-- © 2011 – Vishal (http://SqlAndMe.com)
EXEC master..xp_fixeddrives
drive MB free
—– ———–
C 91884
S 5......
|
|
-
|
|
The most common way to check SQL Server is to use @@VERSION configuration function. It returns version, architecture, OS version and build date for current instance.
-- © 2011 – Vishal (http://SqlAndMe.com)
SELECT @@VERSION AS [Version]
Version
—————&......
|
|
-
|
|
You can use xp_subdirs and xp_dirtree undocumented stored procedures to retrieve a list of child directories under a specified parent directory from file system.
-- © 2011 – Vishal (http://SqlAndMe.com)
EXEC master..xp_subdirs 'C:\\Inetpub'
xp_subdirs – lists only directories w......
|
|
-
|
|
We can use the xp_regwrite undocumented extended stored procedure to write new entries to Windows registry.
You need to provide the key path, A new key will be created if it does not exist.
The following code will add a new entry in startup programs list in registry:
-- © 2011 – Vishal......
|
|
-
|
|
While xp_regread read values from registry under exact path specified. To read instance specific registry entries from registry you can use xp_instance_regenumvalues and xp_instance_regread.
xp_instance_regread translates the given path to instance-specific path in the registry:
for example, execu......
|
|