怎么判断一个值是否在另外的一个值里面 。比如: 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判断 怎么写啊...各位大侠帮帮忙.
set @c='30,29,28'需要得要的结果 set @a='30'
if(...)
@a在@c中
set @a='3'
if(...)
@a不在@c中 这个if判断 怎么写啊...各位大侠帮帮忙.
set @c='30,29,28' set @a='30' IF CHARINDEX(','+@A+',',','+@C+',')>0
PRINT 'Yes'
ELSE
PRINT 'No'
-- 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 行受影响)
存在
*/
fredrickhu 我关注你很久了..
set @c='30,29,28' set @a='30' if charindex(','+@A+',',','+@C+',')>0
print '@a在@c中'
else
print '@a不在@c中'
/*
@a在@c中
*/
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