SQL Server nullif, isnull, isnumeric, cast function example

Source: Internet
Author: User

If (object_id ('t_ test')> 0)
Drop table t_test
Create Table t_test (A SQL _variant, B SQL _variant, C SQL _variant)
Insert into t_test select 1, 1, 'A'
Insert into t_test select 1, getdate (), null
Insert into t_test select 'A', null, 1
Insert into t_test select 3, null, null
Insert into t_test select null, null, null
Select * From t_test
Count (*) -- total
, Count (nullif (1, 1) -- returns 0 forever
, Count (a) -- a quantity
, Count (B) -- number of B
, Count (distinct a) -- A does not repeat the number
, Count (isnull (B, c) -- the number of B or C values not null
, Count (coalesce (a, B, c) -- the number of A, B, or C is not null.
, Count (nullif (A, B) -- A is not equal to the number of B
, Count (nullif (isnumeric (cast (A as varchar (38), 0) -- A is the number of digits.
From t_test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.