use news
create proc Pro_GetNews
as
select * from T_News
go
create proc Pro_GetNewsByTitle
@newstitle varchar(50)
as
select NewsTitle,SUBSTRING(NewsContent,1,20)+'....' as NewContent,CreateTime
from T_News
where NewsTitle like @newstitle;
go
exec Pro_GetNewsByTitle
CREATE proc Pro_GetNewsContent
@newstitle varchar(50)
as
select T1.NewsTitle,SUBSTRING(T1.NewsContent,1,20)+'....' as NewContent,T1.CreateTime
from T_News T1
where T1.NewsTitle like @newstitle or NewsContent like @newstitle ;
go
create proc Pro_GetMaxId
@maxid int out
as
insert into T_News(NewsTitle,NewsContent,NewsCreator,CreateTime,ClassId)
values
('11111','22','003',GETDATE(),'39ec3206-4467-44b4-8fa1-711443eb4ce5');
set @maxid=@@IDENTITY;
go
declare @maxid int;
exec Pro_GetMaxId @maxid out;
print @maxid
create proc Pro_GetMaxId1
@newstitle varchar(64),
@newscontent varchar(max),
@newscreator varchar(8),
@createtime datetime,
@classname varchar(8),
@maxid int out
as
declare @classid uniqueidentifier;
select @classid=T1.ClassId from T_NewsClass T1 where T1.ClassName=@classname;
insert into T_News(NewsTitle,NewsContent,NewsCreator,CreateTime,ClassId)
values
(@newstitle,@newscontent,@newscreator,GETDATE(),@classid);
set @maxid=@@IDENTITY;
go
--执行存储过程
DECLARE @maxid INT;
EXEC Pro_GetMaxId1 '111','11111111','004','1900-02-02','军事',@maxid OUT;
PRINT @maxid;
GO
select* from T_News