|
|
-
|
|
You can user the built-in configuration function @@SERVERNAME to get the server name using TSQL.
It can be used as below:
SELECT @@SERVERNAME AS 'Server Name'
Result Set:
Server Name
————————————————......
|
|
-
|
|
you can use @PARTITION TSQL function to check which partition will be mapped to a specified column value.
For example if you have a partition function with four partitions as below:
-- © 2011 – Vishal (http://SqlAndMe.com)
CREATE PARTITION FUNCTION PartFunc01 (INT)
AS RANGE FOR VAL......
|
|
-
|
|
To calculate the difference between two dates, you can use DATEDIFF() function. The DATEDIFF() function returns the number of days/month/years and time between two dates.
Syntax:
DATEDIFF (date part, start date, end date)
For example, to calculate time left till Independence Day, you can use:
--......
|
|
-
|
|
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
—————&......
|
|