|
|
-
|
|
As you know COALESCE function returns the first non NULL value from the list.
When you execute the followingselect coalesce(null,null,null)
you will get the following error Msg 4127, Level 16, State 1, Line 1
At least one of the arguments to COALESCE mu...
|
|
-
|
|
Julian date is one of the ways to represent date in number format. It is a 7 digit number with first four digits represents the year and last three digits represents the number of days since the first day of that year. There can be many methods to conve...
|
|
-
|
|
Well. You are aware of Computed Columns in SQL Server. In a similar way you can also use Computed Parameters. Consider the following procedure. Create procedure test
(
@datetime datetime,
@date date = @datetime
)
as
select @datetime as date_with_time...
|
|
-
|
|
You can use Ordinal position in the ORDER BY Clause for sorting the resultset. The ordinal position refers the column position in the SELECT statement. Consider the following select statement
select * from
(
select 17 as a,2 as b
union all
select 1 as a,25 as b
) t
order by 1
The above......
|
|
-
|
|
I have posted a blog post about Different ways to find DISTINCT values where I have shown six different ways to find DISTINCT values. Here is the analysis of how long each method takes.
Create a temporary table named #sales_detailscreate table #sales_de...
|
|
-
|
|
Finding distinct values is often needed in such cases like finding distinct items that were sold last month, etc. You can very well use DISTINCT keyword to do this. However there are some other ways too to find distinct values
Consider the following set...
|
|
-
|
|
Often, you are advised not to use * in your SELECT statement. It is because the code that depends on * may be broken if a column is added or removed. If you have a view that uses *, it will not reflect newly added/removed column until the view is ...
|
|
-
|
|
This is just for Fun. The following code is unformatted, unclear and may be confusing. But curious to know the result? Set the result mode of the query window to Text . While you are in Query Window press CONTROL+T and run the following code and see what it returns.
......
|
|
-
|
|
When you write queries that involve datetime columns, it is often needed to remove time part from datetime value to compare only date part. An example would be, you have table called sales_details that has sales_date as one of the columns and you want t...
|
|
-
|
|
I have posted about Creating DATETIME value from integer DATE and integer TIME where I have shown you various methods to create datetime value from integer date and time. Well. Did you know that in MSDB database there is a system function named agent_da...
|
|