日期:2014-05-18  浏览次数:20555 次

字符串数字提取问题
[code=SQL][/code]
[code=SQL][/code]
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER function [dbo].[tdx_te](@dy_type int,@dy_name varchar(8),@dy_fw varchar(30))
returns varchar(4)
as
begin
declare @result varchar(4)
declare @temp varchar(30)


if @dy_name='dd'
begin
select @temp= dy_dd from tdxdb_test 
 if charindex(','+@dy_fw+',' ,ltrim(@temp))>0
 begin 
 select @result=dy_tdx from tdxdb_test
 where @dy_type=dy_type and isdel=0
 end
end
return @result
end 

表结构为:
dy_type dy_tdx dy_dd
  1 买入 11,12


select dbo.tdx_te(1,'dd',12) 返回却为NULL,哪里有误??

------解决方案--------------------
SQL code
select * from tdxdb_test where charindex(','+@dy_fw+',' ,','+ltrim(dy_dd)+',')>0