2015-09-25 74 views
0

我有一個存儲過程,我將3個參數傳遞給該表,並將該表中的所有內容導出,我們將其稱爲dbo.myFinalTable。我想達到兩個目的:使用新數據更新存儲過程中的表

任務#1:

我需要追加的數據,當我再次與我傳遞任何參數執行過程。

我試着在我的最終表創建結束時添加這個,但總行數保持不變。有什麼要做的?

IF (EXISTS (SELECT * 
      FROM INFORMATION_SCHEMA.TABLES 
      WHERE TABLE_SCHEMA = 'myDatabase' 
       AND TABLE_NAME = 'dbo.myFinalTable')) 
BEGIN 
    INSERT INTO dbo.myFinalTable 
     SELECT 
      someValues 
     FROM #tempInWhichIcalulate 
     ORDER BY someOtherStuff 
END 

任務#2:

我執行這樣的:

execute [myStoredProcedure] 'someString', '123', '2013-03-14' 

我希望查詢上面僅當列idtheDate(從dbo.MyFinalTable追加數據;那些列有他們的數據從存儲過程傳遞,在這個示例中值爲'123','2013-03-14')沒有那些已經存在的值。

注:我的過程聲明如下:

alter procedure [myStoredProcedure] 
    (@theString varchar (30), 
    @id varchar (10), 
    @theDate date) 
+0

你好,你能後的'DBO的結果。 FinalTable? @ CM2K – mfredy

+0

重要的列是'theDate'和'id',其餘的只是一些值的計算。不能發佈我的真表 – CM2K

+0

而且這是你的存儲過程'改變過程[myStoredProcedure] ( @theString VARCHAR(30), @id VARCHAR(10), @theDate日期 )'@ CM2K – mfredy

回答

0

如果我明白你的目標,這可能是查詢:

insert into dbo.myFinalTable 
select 
@theString as MyString, 
@id as MyId, 
@theDate as MyDate 
where not exists(select * from dbo.myFinalTable 
       where MyId = @id 
       and MyDate = @theDate)