第一个函数
alter function [dbo].[m_split](@c text,@split varchar(2))    
   returns @t table(col varchar(100))    
   as    
     begin    
       while(charindex(@split,cast(@c as varchar(max))) <>0)    
         begin    
           insert @t(col) values (substring(cast(@c as varchar(max)),1,charindex(@split,cast(@c as varchar(max)))-1))    
             set @c = stuff(cast(@c as varchar(max)),1,charindex(@split,cast(@c as varchar(max))),'')  
         end     
   return  
end 第二个函数
create function [dbo].[Question_split](@P varchar(50))
returns ......这里怎么写 
as
begin
with maco as(
select * from [dbo].[m_split]('简历,面试,跳槽,工作机会,礼仪,' , ',')
)
select * from Question a ,maco b 
where charindex(b.col,a.QuestionClassification)>0
end
return
end
第二个函数中
with maco as(
select * from [dbo].[m_split]('简历,面试,跳槽,工作机会,礼仪,' , ',')
)
select * from Question a ,maco b where charindex(b.col,a.QuestionClassification)>0
不用函数写法查出的是一张表我的意思是怎么定义一个函数[dbo].[Question_split]
内的内容是with maco as(
select * from [dbo].[m_split]('简历,面试,跳槽,工作机会,礼仪,' , ',')
)
select * from Question a ,maco b where charindex(b.col,a.QuestionClassification)>0然后将查出的表
插入到一个表中
return出来

解决方案 »

  1.   

    没人回我自己回个好了
    这样写就行了CREATE function [dbo].[project_split](@p varchar(50))  
    returns table   
    as  
    return(  
     with maco as(  
      select * from [dbo].[m_split]((select cast(KeyWord as varchar(max)) from ProblemCategory where ProblemCName=@p), ',')  
     )  
     select QuestionID,AskUsers,ProblemSubject,Description,QuestionTime,AnswerTime,AnswerState,HotProblems,CommonProblem,cast(QuestionClassification as varchar(max)) as QuestionClassification from Question a ,maco b where charindex(b.col,a.QuestionClassificat
    ion)>0 group by QuestionID,AskUsers,ProblemSubject,Description,QuestionTime,AnswerTime,AnswerState,HotProblems,CommonProblem,cast(QuestionClassification as varchar(max))  
    )
      

  2.   

    不需要用函数
    DECLARE @STR NVARCHAR(200)
    SET @STR=',简历,面试,跳槽,工作机会,礼仪,'
    SELECT * FROM Question AS A WHERE @STR LIKE '%,'+QuestionClassification+',%'
      

  3.   

    好心人啊,我是要运用到ASP。net所以用函数好点,好谢