SQL | Null Function in SQL | ISNULL | COALESCE | IFNULL | NVL

Поділитися
Вставка
  • Опубліковано 7 лют 2023
  • In this video we see the different NULL functions in SQL and see, when and how to use the NULL functions.
    A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value.
    Note: A NULL value is different from a zero value or a field that contains spaces.
    Table used :
    /*
    create table product(
    item varchar(20),
    unitssold int,
    unitsonorder int,
    unitprice int
    )
    */
    /*
    insert into product(item,unitssold,unitsonorder,unitprice)
    values('pen',100,50,20),
    ('book',200,null,30),
    ('pencil',150,50,10),
    ('toys',125,null,40),
    ('bags',100,25,50)
    */
    #data_project_hub
    #dataprojecthub
    #dataanalytics
    #sqlqueries

КОМЕНТАРІ • 10

  • @aceslwin3376
    @aceslwin3376 5 місяців тому +1

    Very thank you for this NULL Problem solve program.😂😂😂🎉🎉🎉😅😅😅

  • @manishprajapat7316
    @manishprajapat7316 4 місяці тому +1

    thanks brother

  • @davidestherohunene2137
    @davidestherohunene2137 6 місяців тому +1

    How do i write a code to return a value on the formatted date column.
    For example, i run a query to change date format from 22/06/25 to change to this format 22-06-25 and the result is null.
    What can i do so the date can show and the null value be replaced with real date of the original dataset.
    Thank you

    • @dataprojecthub
      @dataprojecthub  6 місяців тому

      Hi, I believe the input date column is of string data type. (The following query is based on that assumption)
      --try this query
      -----------------------------------------------------
      select datefromparts([year],[month],[day]) as proper_date --in date data type
      from
      (
      select parsename(replace(date_input,'/','.'),1) as [day],
      parsename(replace(date_input,'/','.'),2) as [month],
      concat('20',parsename(replace(date_input,'/','.'),3)) as [year]
      from
      (select '22/06/25' as date_input) a
      ) b
      --------------------------------------------------
      Here I have used the date '22/06/25' and wrote the query, but you can substitute the date with the actual input column and table.
      Thanks

  • @lerishamendonsa3126
    @lerishamendonsa3126 5 місяців тому +1

    What if have multiple repeated items ,
    How to write a query, can you please help me

    • @dataprojecthub
      @dataprojecthub  5 місяців тому

      Hi, can you give me an example please.

  • @pateldh23
    @pateldh23 Рік тому +1

    How to write sql query to sum of specific field if column value is kg then sum in kg and if value is To then quantity * 1000 and then sum plus sum of kg field

    • @dataprojecthub
      @dataprojecthub  Рік тому

      Hi, actually I did not get the question. Can you please reframe it?

    • @pateldh23
      @pateldh23 Рік тому +1

      @@dataprojecthub suppose I have one table in sql server, cloumns like dt_data_date, vc_material_code, vc_buom, nu_qty. And suppose in vc_buom column if value is 'TO' Means Tone then qty * 1000 and then sum and then it's sum include in KG Coum sum

    • @dataprojecthub
      @dataprojecthub  Рік тому +1

      --this query will create a new column qty_in_kg in which everything will be in kg
      select dt_data_date,
      vc_material_code,
      vc_buom,
      nu_qty,
      case when vc_buom = 'TO' then (nu_qty*1000)
      when vc_buom = 'KG' then nu_qty
      end as qty_in_kg
      from table_name
      --and now if you want to sum up the total quantity based on vc_material_code
      --use the below query
      select vc_material_code
      ,sum(qty_in_kg) as total_quantity
      from
      (
      select dt_data_date,
      vc_material_code,
      vc_buom,
      nu_qty,
      case when vc_buom = 'TO' then (nu_qty*1000)
      when vc_buom = 'KG' then nu_qty
      end as qty_in_kg
      from table_name
      ) a
      group by vc_material_code