• CELKO (12/13/2012)


    My table structure

    Please read just one little book on SQL and RDBMS. Please, just one little book! This is not a table; it has no key; it has to way to ever have a key!! Why did you put the data type as prefix on the column names? That was 1960's BASIC, not SQL! SQL does not use {} like you did. Her is a guess at fixing the disaster.

    CREATE TABLE Client_Shares

    (share_id CHAR(10) NOT NULL PRIMARY KEY,

    lm_id INTEGER,

    ml_id INTEGER,

    is_id INTEGER,

    r_id INTEGER);

    I need to figure out a query that will delete all rows that don't have at least 2 non-null values.

    No, you need to figure out a lot more than that!

    DELETE FROM Client_Shares

    WHERE IFNULL(lm_id, 1) + IFNULL(ml_id, 1)

    + IFNULL(is_id, 1) + IFNULL(t_id, 1) >= 2;

    We don't need a key to solve this problem, so no need for irrelevancies just to satisfy ueber-pedants.

    Please read one book on SQL Server because IFNULL() does not exist in SQL Server.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.