How to replace NULL values with alternate values in SQL Server ?

Assume a scenario where you are trying to get the records from the table where some of the records contains NULL column values and you would like to replace it with an alternate value.

How to replace NULL values with alternate values in SQL Server ?

Use ISNULL method which accepts two parameters
– column name (value)
– alternate value if the value is NULL

The ISNULL method simply checks if the specified expression is NULL and if this is true it replaces the NULL value with the alternate value. The return type value (second parameter) should be of the same type as the first parameter.

Here’s an example of the usage of the ISNULL method.

SELECT JobTitle,
OrganizationLevel = ISNULL(CAST(OrganizationLevel as varchar(200)),'-- No Top Level Found--')
FROM HumanResources.Employee

Read more

How to check if the table exists in a database in SQL Server ?

To check if the table exists in a database in SQL Server , you can use the INFORMATION_SCHEMA view.

How to check if the table exists in a database in SQL Server ?

Here’s a query that gets the table details of the table “Department” in the AdventureWorks2014 database.

use AdventureWorks2014
GO
SELECT * 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_NAME = 'Department'


Read more

Using Expressions for SORT Order in SQL Server

You might want to sort the results of an query in a different order from the traditional sort (Ascending/Descending) order.

For example , you wish to sort the Department records by GroupName and force the GroupName “Manufacturing” to be sorted first.

How to use expression to sort records in SQL Server ?

You could do this by using the expression which would provide the sort order that you require.

Here’s a sample query demonstrating how this can be done.

Use AdventureWorks2014
GO
SELECT * from HumanResources.Department
ORDER BY CASE GroupName   
WHEN 'Manufacturing' THEN NULL      
ELSE GroupName      
END;  

Read more

How to find the Windows OS Build version from Command Line in Windows 10 ?

There are multiple options to find the Windows OS Build version from command line in Windows 10.

How to find the Windows OS Build version from Command Line in Windows 10 ?

The first one is using the command line utility command called “ver” . Just open the command prompt from your Windows 10 machine and enter ver and press enter key which should display the Windows 10 build number.

C:\Users\senthil>ver

Microsoft Windows [Version 10.0.14366]

C:\Users\senthil>


Read more