我尝试使用当前用户登录From
并使用用户输入To
填充。我是新手,但这是我的代码。我想知道是否有sql的内置函数,或者你们中的任何人会如何处理这个?
<pre>
insert into dbo.tbl_Messages
( [DateTime], [From], [To], CC, ID, [Subject], [Message], [Priority], [Read], Read_DateTime, Reply_Req, [Sent], Study_ID )
values ( getDate(), @userID, @userID, ' ', @userID, 'test', 'test', 1, 1, NULL, 0, 0, 0)
</pre>
<pre>
insert into dbo.tbl_Messages
( [DateTime], [From], [To], CC, ID, [Subject], [Message], [Priority], [Read], Read_DateTime, Reply_Req, [Sent], Study_ID )
values ( getDate(), @userID, @userID, ' ', @userID, 'test', 'test', 1, 1, NULL, 0, 0, 0)
</pre>
答案 0 :(得分:0)
在以下行中创建存储过程:
CREATE PROC DoStuff(@UserID int)
AS
BEGIN
insert into dbo.tbl_Messages
( [DateTime], [From], [To], CC, ID, [Subject], [Message], [Priority], [Read], Read_DateTime, Reply_Req, [Sent], Study_ID )
values ( getDate(), SUSER_NAME(), @userID, ' ', @userID, 'test', 'test', 1, 1, NULL, 0, 0, 0)
SELECT ('Insertions Done!')
END
SUSER_NAME()
返回当前用户的用户名。