Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. if else

if else

Scheduled Pinned Locked Moved Database
databasequestionc++
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pnpfriend
    wrote on last edited by
    #1

    does sql has if else statement like c++, vb..? I have following statement SELECT [k1] & ';' & [k2] & ';' & [k3] AS AllK FROM TEST; That Query Statement combine strings of k1,k2,and k3 as k1;k2;k3 and insert it into AllK. However when K1 field has nothing in it, then the result is ;k2;k3 again, when k2 field is emtpy then the result is k1;;k3 so how can i detect whether the field is empty or not to get the result as k1;k3 but not k1;;k3??? Thank you

    B A G 3 Replies Last reply
    0
    • P pnpfriend

      does sql has if else statement like c++, vb..? I have following statement SELECT [k1] & ';' & [k2] & ';' & [k3] AS AllK FROM TEST; That Query Statement combine strings of k1,k2,and k3 as k1;k2;k3 and insert it into AllK. However when K1 field has nothing in it, then the result is ;k2;k3 again, when k2 field is emtpy then the result is k1;;k3 so how can i detect whether the field is empty or not to get the result as k1;k3 but not k1;;k3??? Thank you

      B Offline
      B Offline
      Bo Hunter
      wrote on last edited by
      #2

      I do this quite offen COALESCE function COALESCE( @BarrowDate, GetDate() ) If BarrowDate is null then GetDate() is called. It returns the first non null value I am sure there are others ways Bo Hunter

      1 Reply Last reply
      0
      • P pnpfriend

        does sql has if else statement like c++, vb..? I have following statement SELECT [k1] & ';' & [k2] & ';' & [k3] AS AllK FROM TEST; That Query Statement combine strings of k1,k2,and k3 as k1;k2;k3 and insert it into AllK. However when K1 field has nothing in it, then the result is ;k2;k3 again, when k2 field is emtpy then the result is k1;;k3 so how can i detect whether the field is empty or not to get the result as k1;k3 but not k1;;k3??? Thank you

        A Offline
        A Offline
        Alexandru Savescu
        wrote on last edited by
        #3

        Try using CASE . Best regards, Alexandru Savescu P.S. Interested in art? Visit this!

        1 Reply Last reply
        0
        • P pnpfriend

          does sql has if else statement like c++, vb..? I have following statement SELECT [k1] & ';' & [k2] & ';' & [k3] AS AllK FROM TEST; That Query Statement combine strings of k1,k2,and k3 as k1;k2;k3 and insert it into AllK. However when K1 field has nothing in it, then the result is ;k2;k3 again, when k2 field is emtpy then the result is k1;;k3 so how can i detect whether the field is empty or not to get the result as k1;k3 but not k1;;k3??? Thank you

          G Offline
          G Offline
          Gaurav Bindlish
          wrote on last edited by
          #4

          Write Query like this- Select ISNULL([K1] + ';', '') + ISNULL([K2] + ';', '') + ISNULL([K3] + ';', '') AS AllK FROM TEST Ofcourse I am using the property of SQL that sum of a NULL string with another string is NULL. So if any of the K1, K2 or K3 field is NULL, [K1] + ';' will give NULL. HTH. Gaurav

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups