参考一下create function getstr(@课程编号 int)
returns varchar(2000)
as 
begin
declare @str varchar(2000)
set @str=''
select @str=@str+','+rtrim(上课班级) from 表 where 课程编号=@课程编号
select @str=right(@str,len(@str)-1) where @str<>''
return @str
end

解决方案 »

  1.   

    Select a.corp_id from corp_info a,code_corp_vocation b 
    where b.description = '油' and 
    charindex(cast(b.vocation as varchar),a.vocation) > 0
      

  2.   

    刚才搞反了
    这个应该更有帮助CREATE proc pd_AJ_IGStat @IGNum char(10)
    as
    select * from tb_d_AJ_InspectGroup where  charindex(','+cast(IGID as varchar(10))+',',','+(select IGID from tb_w_AJ_IGStat where IGNum=@IGNum))>0
    GO
      

  3.   

    Select a.corp_id , b.description  as '油'
    from corp_info a,code_corp_vocation b 
    where b.description = '油' and b.vocation=a.vocation
      

  4.   

    Select a.corp_id from corp_info a,code_corp_vocation b 
    where b.description = '油' and 
    a.vocation like '%'+cast(b.vocation as varchar)+'%'
      

  5.   

    解释:
    Select a.corp_id , b.description  as '油'
    from corp_info a,code_corp_vocation b 
    where b.description = '油' and b.vocation=a.vocation
    在建表的时候把vocation按一种类型输入.
    如果按多种类型输入你可以再把用一条语句查询一下corp_info .vocation 只要包含 对应"油"的就可以选.具体的要看用的具体数据库 . corp_id       vocation
           1           ,2,3,    说明包含“钢材” 和“木材”
           2           ,1,3,    说明包含 “油”和“木材”
           3           ,1,3,4,
    矫正一点,正规的数据库设计很少把 不同的vocation放在一条记录里.因为这样没有起到真正数据结构化.建议你这样(设定 corp_id       vocation 为唯一索引或主键):corp_id       vocation
           1           2    说明包含“钢材” 
       1     3   “木材”
           2           1    说明包含 “油”
        2     3  “木材”
           3           1
        3     3
        3     4 
    这样的数据比原来的清晰的多.
      

  6.   

    谢谢了~~~问题已经解决~~~
    哎~~~我们公司的数据库  is  terrible !!!!