Add row to the SQL result?

  • Dear All,

    I need to add a row to the result of SQL statement.

    The Sql Statement is:

    select ID, name from myTable;

    the result:

    ID name

    1 name1

    2 name2

    3 name3

    the previous result comes from the table, but I need to add a row in the result which is not in the table.

    Is it possible to display a row in the result which does not exist in the table?

    Regards

  • obarahmeh (11/5/2009)


    Dear All,

    I need to add a row to the result of SQL statement.

    The Sql Statement is:

    select ID, name from myTable;

    the result:

    ID name

    1 name1

    2 name2

    3 name3

    the previous result comes from the table, but I need to add a row in the result which is not in the table.

    Is it possible to display a row in the result which does not exist in the table?

    Regards

    take the result in temporary table and add a new row and list it

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • you have an advantae with this that, if any duplicates are there, its removed.

    Create table #t(ID int, Name varchar(10))

    INSERT INTO #t VALUES (1, 'abc')

    INSERT INTO #t VALUES (2, 'def')

    INSERT INTO #t VALUES (3, 'ghi')

    SELECT * from #t

    UNION

    SELECT 4, 'jkl'

    ---------------------------------------------------------------------------------

  • Also union can be used

    Select UserName from table B

    Union

    Select somecolumn as UserName from table B

Viewing 4 posts - 1 through 3 (of 3 total)

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