IF EXISTS(SELECT *FROM SYSOBJECTS WHERE NAME='spSelectTestList')
DROP PROC spSelectTestList
go
create PROCEDURE [dbo].[spSelectTestList]
(
@DataType varchar(10), --日期条件
@TestType char(3), --产品类型条件
@TestListId char(18) OUTPUT, --输出最后一条记录
@TestSql varchar(300) OUTPUT --输出存储过程中的SQL语句
)
AS
--declare @Sqlstr1 varchar(50)
--declare @Sqlstr2 varchar(50)
declare @Sqlstr varchar(300) --输出存储过程中的SQL语句
--set @Sqlstr1='select top 1'+ ''' +@TestListId+ '''
--set @sqlstr2='=TestListId from TestTemp '
--set @Sqlstr=@Sqlstr1+@Sqlstr2
set @Sqlstr='select top 1'+ ''' +@TestListId+ ''' +'=TestListId from TestTemp '
if @DataType is not null
begin
set @Sqlstr=@Sqlstr+ 'where SUBSTRING(rtrim(Testlistid),len(rtrim(TestListId))-14,LEN(Rtrim(TestListId))-8)='+ '''' +@DataType+ ''''
end
if @TestType is not null
begin
set @Sqlstr=@Sqlstr+' and TestListId like ' + '''' +'%'+@TestType+'%'+ ''''
end
if @Sqlstr is not null
begin
set @
7031




被折叠的 条评论
为什么被折叠?



