关于SQL语句的问题(50分)

  • 主题发起人 主题发起人 Hexi
  • 开始时间 开始时间
H

Hexi

Unregistered / Unconfirmed
GUEST, unregistred user!
我在sql7.0中执行下面创建触发器,出现错误
“Server: Msg 2739, Level 16, State 1, Procedure trLetter_Insert, Line 4
The text, ntext, and image data types are invalid for local variables.

该如何解决,我的出发器能否简化?

CREATE TRIGGER [trLetter_Insert] ON [tbLetter]
FOR INSERT
AS
begin
declare @UserID int, @RegDateTime datetime, @NeedEmail bit, @LetterID int, @Content text;
select @UserID=UserID, @RegDateTime=RegDateTime,@Content=Content, @NeedEmail=NeedEmail, @LetterID=LetterID from Inserted;
Insert tbAnswer (UserID, RegDateTime, Content, NeedEmail, LetterID);
values (@UserID, @RegDateTime, @Content, @NeedEmail, @LetterID)
end
 
DECLARE
{
{@local_variable data_type}
| {@cursor_variable_name CURSOR}
} [,...n]


data_type
Is any system-supplied or user-defined data type. A variable cannot
be of text, ntext, or image data type. For more information about
system data types, see Data Types. For more information about user-
defined data types, see sp_addtype.
 
难道用SQL语句不能插入一条带Text字段的记录吗?
 
为什么这麽麻烦?可以简化:
Insert tbAnswer (UserID, RegDateTime, Content, NeedEmail, LetterID)
values (select UserID, RegDateTime, Content, NeedEmail, LetterID
from Inserted )
 
Insert tbAnser select * from Inserted
 
多人接受答案了。
 
后退
顶部