Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009

    Question Unanswered: problem with if statement

    There are two tables I have to insert data into table two on following conditions

    Table 1 with following 4 columns and two rows .................,columns are [colADD1][col ADD2][Zip1][Zip2 ] and two rows are row A & Row B

    [colADD1] [colADD2][Zip1][Zip2]
    rowA 12 22 1 4
    rowB null 9 null 80

    Table 2 with 2 columns
    12 1
    22 4

    If coladd1 is not null and coladd2 is not null and l zip1 is not null and zip2 is not null
    Then there will be two rows inserted in [table 2]

    If coladd1 is null and zip1 is null but coladd2 is not null and zip2 is not null than one row is inserted in table 2 which is value of coladd2 and zip2

    If coladd2 is null and zip2 is null but coladd1 is not null and zip1 is not null than one row is inserted in table 2 which is value of coladd1 and zip1

    I need a code specifying above conditions
    When I am using
    IF (table1.coladd1<> null)
    It throws an error with saying multipart identifier could not be bound

    I am new to this thing pls help
    Last edited by amitwadhawan123; 01-05-10 at 23:13.

  2. #2
    Join Date
    Oct 2009
    Don't know where you are using this IF condition, Tablename.Columnname can be used in the select statement, without from clause not possible to use the column name in condition.

    Any way for your case try this script,

    insert into [Table 2]
    select colADD1,Zip1 from [Table 1] where not(colADD1 is null)
    select colADD2,Zip2 from [Table 1] where not(colADD2 is null)

  3. #3
    Join Date
    Jan 2007
    Provided Answers: 12
    You don't seem to understand nulls completely. It will be worth your while reading this thread to try get a better appreciation of what nulls are first.
    Home | Blog

Posting Permissions

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