2013-06-03 40 views
2

插入值,我有以下保存,我想在SQL Server 2008中如何執行存儲過程中多次表

USE [Students] 
GO 

DECLARE @return_value int 

EXEC @return_value = [School].[Student_Entry] 
     @StudentName = N'Kenny', 
     @StudentClass = N'1' 

SELECT 'Return Value' = @return_value 

GO 

執行運行上面的存儲過程進入在叫學生SQL Server表值的過程。但我喜歡這樣的100個值是否有更簡單的方法來將多個值插入在一起? 或者我將不得不每次爲每個值寫上面的執行語句?

+0

這取決於在那裏的100個值現在是,是否必須使用存儲過程或允許繞過它並直接進入表。 – RBarryYoung

+0

RBarryYoung - 是的,我必須使用存儲過程。這些值在紙上,我將不得不手動插入它們。 – NoviceMe

+0

您是否在Management Studio(SSMS)中執行存儲過程? – RBarryYoung

回答

-1

那麼假設你使用SSMS,那麼你就可以做到這一點的老同學:使EXEC命令爲單行線,以「#」替換參數,剪切和粘貼該行的100倍。然後用列表中的實際參數替換「#」並執行。

下面是與10號線的例子,讓你開始:

USE [Students] 
GO 

DECLARE @rt int 

EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 
EXEC @rt = [School].[Student_Entry] @StudentName=N'#', @StudentClass=N'#'; SELECT 'Return Value'[email protected] 

GO 
+2

爲什麼隨機downvote? – RBarryYoung

+1

更多的驅動器,通過向下票對這個技術上是正確的,高效的和接受的答案(和唯一的答案存在),但沒有一個人與禮貌(或勇氣)說爲什麼,更不用說智慧提供一個更好的答案。我想這裏還有一個無知規則文化的例子。 – RBarryYoung

+0

即使我不知道更好的方法來實現這一點,但你的解決方案並不是很好。想象一下誰有時間粘貼100次。如果我們想要插入不同的值,那麼也會改變這一點。 :) – Mike