plz i need help!!!!

  • i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

    need ur help:-)

  • almany_13 (1/27/2013)


    i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

    need ur help:-)

    Hi...welcome to the site.

    its a bit difficult to help you....I cant see what you can see....perhaps if you gave us the code for your query and some example data and expected results...we may be able to help

    if you are unsure how to provide this...please post back...I assume you are using SQL 2005 ?

    regards

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • --create a table for some sample data

    IF OBJECT_ID('tempdb..#TempTable') IS NOT NULL

    DROP TABLE #TempTable

    CREATE TABLE #TempTable (

    [ID] INT NOT NULL,

    [Col1] INT NULL,

    [Col2] INT NULL,

    PRIMARY KEY (ID))

    --insert random numbers with a few nulls tossed in

    INSERT INTO #TempTable

    SELECT 1,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1

    UNION

    SELECT 2,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1

    UNION

    SELECT 3,NULL,ABS(CAST(NEWID() AS BINARY(6))%10)+1

    UNION

    SELECT 4,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1

    UNION

    SELECT 5,ABS(CAST(NEWID() AS BINARY(6))%10)+1,NULL

    UNION

    SELECT 6,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1

    --raw table

    SELECT * FROM #TempTable ORDER BY ID

    --Col1+Col2 = Col3

    SELECT

    ID

    ,Col1

    ,Col2

    ,Col3 = ISNULL(Col1,0) + ISNULL(Col2,0)

    FROM

    #TempTable

    ORDER BY

    ID

  • almany_13 (1/27/2013)


    Did not understand the question properly. But can you please try the below script.

    SELECT name, (CASE WHEN(salary) <= 0 THEN NULL ELSE salary END)

    + (CASE WHEN(bonuses) <= 0 THEN NULL ELSE bonuses END) ) as total

    FROM YourTableName

    _____________________________________________
    One ounce of practice is more important than tonnes of dreams

  • No need for CASE here at all.

    SELECT Name,

    Total = ISNULL(Salary,0) + ISNULL(Bonuses,0)

    FROM dbo.YourTable

    ;

    If you insist on ANSI/ISO code, you can replace ISNULL with COALESCE. I use ISNULL to make sure the datatype stays the same as the first operand and, over millions of rows, is a bit faster than COALESCE.

    As a note for future posts, please read and heed the article at the first lik in my signature line below. Thanks.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Yes Jeff,

    I had that thing in my mind. But in the first post he wants "result with a null value". I should have post both the scripts 😀

    Thanks Jeff

    almany_13 (1/27/2013)


    i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

    need ur help:-)

    _____________________________________________
    One ounce of practice is more important than tonnes of dreams

  • C.K.Shaiju (1/28/2013)


    Yes Jeff,

    I had that thing in my mind. But in the first post he wants "result with a null value". I should have post both the scripts 😀

    Thanks Jeff

    almany_13 (1/27/2013)


    i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

    need ur help:-)

    Yet in the post where you offered your solution, you quoted the post where the op finally clarified and said "0 or noting[sic]". Not sure what wasn't clear about that.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Correct. In the first post he wants NULL and 2nd post 0 or Nothing (NULL). Thought he might be doing something with NULL. That's why I posted that script as a solution for both of his posts.

    _____________________________________________
    One ounce of practice is more important than tonnes of dreams

  • Thank societies... and I appreciate your help 😉

  • C.K.Shaiju (1/28/2013)


    Correct. In the first post he wants NULL and 2nd post 0 or Nothing (NULL). Thought he might be doing something with NULL. That's why I posted that script as a solution for both of his posts.

    Ah! Got it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This looks like a school assignment. I think rather then giving him code we should send him some good tutorials.

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply