码迷,mamicode.com
首页 > 其他好文 > 详细

如何创建存储过程

时间:2017-04-28 23:43:24      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:_id   存储过程   identity   drop   ide   table   system   err   text   

IF OBJECT_ID (‘p_GetData‘,‘p‘) IS NOT NULL
DROP PROCEDURE p_GetData;
GO

CREATE PROCEDURE p_GetData
-- Add the parameters for the stored procedure here
@SourceID varchar(255),
@Keyword varchar(255)=‘‘,
@Keyword1 varchar(255)=‘‘,
@Keyword2 varchar(255)=‘‘,
@Keyword3 varchar(255)=‘‘,
@Keyword4 varchar(255)=‘‘,
@Keyword5 varchar(255)=‘‘,
@Keyword6 varchar(255)=‘‘,
@sOrder varchar(255)=‘‘,
@sort varchar(255)=‘‘,
@startRow int=‘‘,
@endRow int=‘‘
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here

declare @sSql varchar(1000)

if @sOrder!=‘‘
begin
  set @sOrder=‘ order by ‘+@sOrder
end

if @sort!=‘‘
begin
  set @sOrder=@sOrder+‘ ‘+@sort
end

if object_id(‘tempdb..##test‘) is not null
begin
  drop table ##test
end

if @SourceID=‘test1‘
begin
  set @sSql=‘SELECT IDENTITY(int,1,1) as rowId,* into ##test FROM test WHERE test like ‘‘%‘+@Keyword+‘%‘‘ ‘+@sOrder
  exec (@sSql)
  select * from ##test where rowId between @startRow and @endRow
end

if @SourceID=‘comp‘
begin
  set @sSql=‘select IDENTITY(int,1,1) as rowId,test as text into ##test from system_table‘
  exec (@sSql)
  select * from ##test
end

if @SourceID=‘login‘
begin
  set @sSql=‘‘
  if @Keyword=‘‘
  begin
    set @sSql=‘useridempty‘
  end
  if @Keyword1=‘‘
  begin
    set @sSql=‘passwordempty‘
  end

  print @sSql
  if @sSql=‘‘
  begin
    print ‘123‘
    --select * from USERFLM where userid=‘sa‘ and pwd=‘123‘

  if not exists(select * from USERFLM where userid=@Keyword and pwd=@Keyword1)
  begin
    set @sSql=‘error‘
  end
end
print @sSql
select @sSql as result

end

-- exec (@sSql)
--
-- if @startRow!=‘‘ and @endRow!=‘‘
-- begin
-- select * from ##test where rowId between @startRow and @endRow
-- end
-- else
-- begin
-- select * from ##test
-- end

END
GO

如何创建存储过程

标签:_id   存储过程   identity   drop   ide   table   system   err   text   

原文地址:http://www.cnblogs.com/qshhq/p/6783561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!