ALTER PROCEDURE [dbo].[getReply] @PaperID int,
@topicID int
AS
BEGIN
SET NOCOUNT ON;
declare @tb table(ID int identity(1,1),replyUser nchar(10),replyTime datetime,replyContent nvarchar(max),UserContent nvarchar(200))
insert into @tb
select r.replyUser AS replyUser,r.replyTime AS replyTime,r.replyContent AS replyContent,u.UserContent AS UserContent
from Forum_User u
inner join Forum_Reply r on r.replyUser=u.UserID
where r.topicID=@topicID AND r.PaperID=@PaperID
SELECT * from @tb
END
@topicID int
AS
BEGIN
SET NOCOUNT ON;
declare @tb table(ID int identity(1,1),replyUser nchar(10),replyTime datetime,replyContent nvarchar(max),UserContent nvarchar(200))
insert into @tb
select r.replyUser AS replyUser,r.replyTime AS replyTime,r.replyContent AS replyContent,u.UserContent AS UserContent
from Forum_User u
inner join Forum_Reply r on r.replyUser=u.UserID
where r.topicID=@topicID AND r.PaperID=@PaperID
SELECT * from @tb
END
ALTER PROCEDURE [dbo].[getReply] @PaperID int,
@topicID int
AS
BEGIN
SET NOCOUNT ON;
declare @tb table(ID int identity(1,1),replyUser nchar(10),replyTime datetime,replyContent nvarchar(Max),UserContent nvarchar(200)
exec('insert into' +@tb+' select r.replyUser AS replyUser,r.replyTime AS replyTime,r.replyContent AS replyContent,u.UserContent AS UserContent from Forum_User u inner join Forum_Reply r on r.replyUser=u.UserID where r.topicID='+@topicID+' AND r.PaperID='+@PaperID )
exec('SELECT * from '+@tb)
END
inner jion Forum_Reply r 不用别名就是了
@topicID int
AS
BEGIN
SET NOCOUNT ON;
declare @tb table(ID int identity(1,1),replyUser nchar(10),replyTime datetime,replyContent nvarchar(Max),UserContent nvarchar(200)
insert into @tb select r.replyUser AS replyUser,r.replyTime AS replyTime,r.replyContent AS replyContent,u.UserContent AS UserContent from Forum_User u inner join Forum_Reply r on r.replyUser=u.UserID where r.topicID=@topicID AND r.PaperID=@PaperID
SELECT * from @tb
ENDEND 错误是消息 156,级别 15,状态 1,过程 getReply,第 18 行
关键字 'insert' 附近有语法错误。 之前是没有错的,我再加上INNER JOIN链接上 Forum_Reply表才错的! 单独把其中的select语句提出来也是没有错的!
declare @tb table(ID int identity(1,1),replyUser nchar(10),replyTime datetime,replyContent nvarchar(Max),UserContent nvarchar(200))加括号
---存储过程这样ALTER PROCEDURE [dbo].[getReply] @PaperID int,
@topicID int
AS
SET NOCOUNT ON;
declare @tb table(ID int identity(1,1),replyUser nchar(10),replyTime datetime,replyContent nvarchar(Max),UserContent nvarchar(200)
insert into @tb select r.replyUser AS replyUser,r.replyTime AS replyTime,r.replyContent AS replyContent,u.UserContent AS UserContent from Forum_User u inner join Forum_Reply r on r.replyUser=u.UserID where r.topicID=@topicID AND r.PaperID=@PaperID
SELECT * from @tb
set nocount off