Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2011
    Posts
    30

    Unanswered: IF statement in mssql 2005

    hi all,

    From my reading around i notice that mssql 2005 does not use the If then Else as in programing.

    I see they use CASE, but i am having trouble using it.

    For example i want to run to compare 2 items and if they arent equal to each other a third item is null..... this is what my if structure on paper looks like

    IF RSITEM.Itemid <> RSITEMDESCRIPTION.Itemid
    Then
    RSITEMDSCRIPTION.ItemDesc = 'null'
    Else
    use RSTITEMSCRITPION.ItemDesc

    I hope i am making sense.
    Last edited by drdre; 08-09-11 at 18:42.

  2. #2
    Join Date
    Aug 2011
    Posts
    13
    I gave an example of this in your previous post

    ColumnName = Case when RSITEM.Itemid <> RSITEMDESCRIPTION.Itemid THEN NULL ELSE RSTITEMSCRITPION.ItemDesc END

    Replace ColumnName with what you want to name the column

    By the way, 'null' will not show a null column, it actually prints null

  3. #3
    Join Date
    Feb 2011
    Posts
    30
    Thanks chris.. i now realize that after reading over the whole post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •