promotion image of download ymail app
Promoted
Anonymous
Anonymous asked in 電腦與網際網路軟體 · 1 decade ago

SQL Sever2005 合併的問題

我想問一下

合併如果使用 union 的話

若兩個資料表中有相同的

union只會留一個顯示

若要兩筆都顯示的話要用union all

那如果我想要把兩個資料表合併

不使用union all 這個指令

卻想要做到跟她一樣的效果

我該怎樣合併才可以呢??

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    store procedure

    a_table >> insert into temp-table

    b_table >> insert into temp-table

    c_table >>...

    select * from temp-table

    給我 table-schema (layout)

    我寫給你

    2007-12-13 21:33:28 補充:

    CREATE PROCEDURE sp_Temp_Ins_Select

    AS

    SELECT

    p.pub_id,p.pub_name,t.pubdate

    INTO #TMPTABLE_2

    FROM

    titles t INNER JOIN publishers p ON p.pub_id=t.pub_id

    WHERE pubdate = (SELECT MIN(x.pubdate) FROM titles x WHERE x.pub_id=t.pub_id)

    2007-12-13 21:33:33 補充:

    INSERT INTO #TMPTABLE_2

    SELECT

    p.pub_id,p.pub_name, (CAST('1900-01-01' AS DATETIME ))

    FROM

    publishers p

    WHERE NOT EXISTS (SELECT * FROM titles x WHERE x.pub_id=p.pub_id)

    Source(s): SAP / Oracle / DB2顧問 OpenSource ERP Adempiere 北美與中國(含台灣區)技術支持團隊
    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.