34,593
社区成员
发帖
与我相关
我的任务
分享
declare @StandardLoadAmount real
set @StandardLoadAmount = ' '
select @StandardLoadAmount
create procedure udsp_SelectTruckType
@Name nvarchar(16)=null,
@StandardLoadAmount real=null
as
declare @where varchar(100)
set @where =''
if @Name is not null
set @where=@where+' and ttf_Name='''+@Name+''''
if @StandardLoadAmount is not null
set @where=@where+' and ttf_StandardLoadAmount='+ltrim(@StandardLoadAmount)
declare @SelectStatement nvarchar(4000)
set @SelectStatement='select ttf_Index 流水号,ttf_Name 名称,ttf_StandardLoadAmount 标重 from udfdt_TruckType where 1=1'+@where
execute(@SelectStatement)
go
--调用
exec udsp_SelectTruckType null,43
exec udsp_SelectTruckType '34',null
等等。
declare @StandardLoadAmount real
set @StandardLoadAmount = ' '
select isnumeric(@StandardLoadAmount) -- return 1
select isnumeric(' ') -- return 0
declare @StandardLoadAmount real
set @StandardLoadAmount = ' '
select datalength(rtrim(ltrim(@StandardLoadAmount)))
/*
---
1
*/
--改成这样:
create procedure udsp_SelectTruckType
@Name nvarchar(16),
@StandardLoadAmount real
as
declare @where varchar(100)
set @where =''
if datalength(rtrim(ltrim(@Name)))!=0
set @where=@where+' and ttf_Name='''+@Name+''''
if datalength(rtrim(ltrim(@StandardLoadAmount)))!=0
set @where=@where+' and ttf_StandardLoadAmount='+ltrim(@StandardLoadAmount)
declare @SelectStatement nvarchar(4000)
set @SelectStatement='select ttf_Index 流水号,
ttf_Name 名称,
ttf_StandardLoadAmount 标重
from udfdt_TruckType where 1=1'+@where
execute(@SelectStatement)
go
set @SelectStatement='select ttf_Index 流水号,
ttf_Name 名称,
ttf_StandardLoadAmount 标重
from udfdt_TruckType where ttf_Name='''+isnull(@Name,'ttf_Name')+
''' and ttf_StandardLoadAmount='+isnull(convert(nvarchar(22),@StandardLoadAmount),'ttf_StandardLoadAmount')
alter procedure udsp_SelectTruckType
@Name nvarchar(16),
@StandardLoadAmount real
as
if datalength(rtrim(ltrim(@Name)))=0
set @Name=null
if datalength(rtrim(ltrim(@StandardLoadAmount)))=0
set @StandardLoadAmount=null
select ttf_Index 流水号,
ttf_Name 名称,
ttf_StandardLoadAmount 标重
from udfdt_TruckType where ttf_Name=isnull(@Name,ttf_Name)
and ttf_StandardLoadAmount=isnull(@StandardLoadAmount,ttf_StandardLoadAmount)
go
select ttf_Index 流水号,
ttf_Name 名称,
ttf_StandardLoadAmount 标重
from udfdt_TruckType where ttf_Name=ttf_Name and ttf_StandardLoadAmount=0