Pages

Social Icons

Tuesday 28 January 2014

Get Current time zone time in SQL

Hi,

Below query will give the time according to time zone

DECLARE @TIMZONE VARCHAR(6)
DECLARE @USERTIMZONE VARCHAR(50) = 'HAWAIIAN STANDARD TIME'

SELECT @TIMZONE = CASE @USERTIMZONE
WHEN 'CENTRAL STANDARD TIME' THEN '-06:00'
WHEN 'EASTERN STANDARD TIME' THEN '-05:00'
WHEN 'HAWAIIAN STANDARD TIME' THEN '-10:00'
WHEN 'MOUNTAIN STANDARD TIME' THEN '-07:00'
WHEN 'PACIFIC STANDARD TIME' THEN '-08:00' END

SELECT CAST(SWITCHOFFSET(TODATETIMEOFFSET(GETUTCDATE(), '+00:00'),@TIMZONE) AS DATE)

Thanks,
RS

Monday 27 January 2014

Definition and information of sql object

Hi,

Below are the three ways by which we can get the definition and information of sql object like view, procedure or function

SELECT definition, uses_ansi_nulls, uses_quoted_identifier, is_schema_bound
FROM sys.sql_modules
WHERE object_id = OBJECT_ID('<storedProcedure_Name>');

SELECT OBJECT_DEFINITION (OBJECT_ID('<storedProcedure_Name>')) AS ObjectDefinition;

EXEC sp_helptext '<storedProcedure_Name>'

Thanks,
RS

CONCAT_NULL_YIELDS_NULL Options

Hi,

What is the result of below query?

SELECT 'ABC' + NULL
Ans: Null

Now If I want this result as 'ABC' then what I have to do.

In this case we can use CONCAT_NULL_YIELDS_NULL options in sql.

SET CONCAT_NULL_YIELDS_NULL OFF

SELECT 'ABC' + NULL

Now the above query will give us the result 'ABC'

Below are the values for CONCAT_NULL_YIELDS_NULL options

Required value : ON
Default server value : ON
Default OLE DB and ODBC value : ON
Default DB-Library value : OFF

Thanks,
RS