From: http://www.cnblogs.com/wghao/archive/2009/11/22/1608285.html
Use test
Go
/* Isnull () function test
Isnull (check_expression, replacement_value)
*/
1. The data type is the same, but the length is different.
Declare @ x nvarchar (5 ),
@ Y nvarchar (50)
Set @ Y = n' 123456'
Print isnull (@ X, @ Y) -- @ Y is intercepted, and "12345" is returned"
Go
2. Different data types (nvarchar-> INT)
Declare @ x int,
@ Y nvarchar (50)
Set @ Y = n' 123456'
Print isnull (@ X, @ Y) + n'1' -- convert it to the int data type and add "1". Therefore, "123457" is returned"
Go
3. Different data types (INT-> nvarchar)
Declare @ x nvarchar (50 ),
@ Y int
Set @ Y = n' 123456'
Print isnull (@ X, @ Y) + n'1' -- convert it to the nvarchar data type first, and then add "1", so "1234561" is returned"
Go
4. Different data types (nvarchar-> uniqueidentifier)
Declare @ x uniqueidentifier,
@ Y nvarchar (50)
Set @ Y = n' 123456'
Print isnull (@ X, @ Y) -- receive the error message: "failed to convert string to uniqueidentifier ".
Go
5. An interesting test (nvarchar --> null)
Declare @ Y nvarchar (50)
Set @ Y = n' 123456'
Print isnull (null, @ Y) + n'1' -- indicates that when check_expression is null, the returned data type is replacement_value, so the nvarchar type of @ Y is returned: "1234561"
6. An interesting test (int --> null) -- to verify the 5th examples.
Declare @ Y int
Set @ Y = n' 123456'
Print isnull (null, @ Y) + n'1' -- indicates that when check_expression is null, the returned data type is replacement_value. Therefore, the int type of @ Y is returned: "123457"
Go