我目前有以下存儲過程;存儲過程計算和性能改進
CREATE PROCEDURE web.insertNewCampaign
(
@tmp_Id BIGINT,
@tmp_Title VARCHAR(100),
@tmp_Content VARCHAR(8000),
@tmp_Pledge DECIMAL(7,2),
[email protected]_Recipients BIGINT,
@tmp_Date DATETIME,
@tmp_Private BIT,
@tmp_Template BIGINT,
@tmp_AddyBook BIGINT
)
AS
declare @recipients BIGINT
declare @tmp_IDENTITY BIGINT
declare @fave BIGINT
declare @allocation VARCHAR(50)
--insert campaign data
BEGIN TRAN
SELECT @recipients = addMaster_NoRecipients FROM tbl_AddressBookMaster
WHERE addMaster_UserId = @tmp_Id AND addMaster_Key = @tmp_AddyBook;
INSERT INTO TBL_CAMPAIGNS ([campaign_MemberId], [campaign_Title], [campaign_Content], [campaign_Pledge], [campaign_Date], [campaign_Private], [campaign_Template], [campaign_AddressBook], [campaign_Recipients])
VALUES (@tmp_Id, @tmp_Title, @tmp_Content, @tmp_Pledge, @tmp_Date, @tmp_Private, @tmp_Template, @tmp_AddyBook, @recipients)
SELECT @tmp_IDENTITY = SCOPE_IDENTITY() --this returns the newly added IDENTITY ID
COMMIT
......
所以我有2個問題:
1)怎樣除以@recipients @tmp_Pledge給@allocation如:(@分配= @tmp_Pledge/@recipients)
2)是否有可能通過@allocation將這些語句複合爲一個更有效的語句,並將其有效地作爲值插入到列[campaign_RecipShare]中,並減少對這些已聲明變量的需求?
很多感謝您提供任何問題的任何幫助。
;-)
看起來不錯,但sql管理器不會編譯它。它說addMaster_NoReceipients的第二個引用不是一個有效的列名。 – Munklefish 2009-08-26 13:49:59