How to get Day of Year from date in SQL Server
Method #1: Using DATEPART Function Method #2: Using DATENAME Function
Method #1: Using DATEPART Function Method #2: Using DATENAME Function
Get First day of current week: SELECT DATEADD(wk, DATEDIFF(wk, 0, GETDATE()-1), 0) Get Last day of current week: SELECT DATEADD(wk, DATEDIFF(wk, 0, GETDATE()),6) Get First day of current month: SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) Get Last day of current month: SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,-1) Get First day of current quarter: SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), …
YES. Very much needed! GO is a batch separator in SQL. Go is essentially is SSMS code rather than a regular T-SQL code. Batch is a set of SQL statements sent together to SQL Engine. It is used to commit a set of queries or a batch to database. It …
To find out when your SQL Server was last booted or re-started, we can run any below queries – SELECT sqlserver_start_time FROM sys.dm_os_sys_info; SELECT login_time FROM sys.dm_exec_sessions WHERE session_id = 1; SELECT start_time from sys.traces where is_default = 1; SELECT crdate FROM sysdatabases WHERE name=’tempdb’; SELECT create_date FROM sys.databases WHERE …
An indexed view is a view with a unique clustered index created on it. It is also called Materialized View. If a query contains references to columns that are present both in an indexed view and base tables, and the query optimizer determines that using the indexed view provides the …
Why do we have Right Join in SQL, if we can use Left Join to get same result as of Right Join by just changing the position of tables? Most of the people has concern on Right Outer Join. Why it is needed. This is useless, blab blab… The answer …