怎么判断一个值是否在另外的一个值里面 。比如: declare @a varchar(10),@c varchar(100)
  set @c='30,29,28'需要得要的结果  set @a='30'
  
   if(...)
    @a在@c中
 set @a='3'
    if(...)
    @a不在@c中 这个if判断 怎么写啊...各位大侠帮帮忙.

解决方案 »

  1.   

    select * from c where charindex(','+@a+',',','+@s+',')>0
      

  2.   

    declare @a varchar(10),@c varchar(100)
      set @c='30,29,28'  set @a='30'  IF CHARINDEX(','+@A+',',','+@C+',')>0
           PRINT 'Yes'
      ELSE
           PRINT 'No'
      

  3.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(小F,向高手学习)
    -- Date    :2011-09-26 15:48:23
    -- Verstion:
    --      Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86) 
    -- Apr 22 2011 11:57:00 
    -- Copyright (c) Microsoft Corporation
    -- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
    --
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([col] varchar(8))
    insert [tb]
    select '30,29,28'
    --------------开始查询--------------------------
     declare @a varchar(10)
     set @a='30'
     if exists(select 1 from tb where charindex(','+@a+',',','+col+',')>0)
     print '存在'
     else
     print '不存在'----------------结果----------------------------
    /* 
    (1 行受影响)
    存在
    */ 
      

  4.   

    谢谢大家了...
    fredrickhu  我关注你很久了..
      

  5.   

    declare @a varchar(10),@c varchar(100)
      set @c='30,29,28'  set @a='30'  if charindex(','+@A+',',','+@C+',')>0
           print '@a在@c中'
      else
           print '@a不在@c中'
           
    /*
    @a在@c中
    */
      

  6.   

    我的问题也实现了 准备结贴了 谢谢大家 if ((@attendanceType='11' or @attendanceType='19') and @grade='0')
    BEGIN
       SELECT   @hospitalvalue=VALUE FROM   dbo.SystemConfig sc WHERE     sc.code = 'C1068'  AND sc.policyPeriod = @policyPeriod
       
         IF CHARINDEX('@'+@hospitalId+'@','@'+@hospitalvalue+'@')>0  --使用本机构的目录
           SET @upperhospital=@hospitalId
      ELSE
           select @upperhospital=upperhospital from hospital where hospitalid=@hospitalId