我目前有以下存储过程;存储过程计算和性能改进
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