数据库表的一列1,信息如下
北方
东莞
福州
厦门
华中
南京
山东
上海
深圳
苏州
西南
粤西
中山
佛山
浙江
我想写一个语句对当前的一个常量(如:山东青岛),把包含数据库列1的那一条的信息查找出来,这个要怎么写?
查找结果为:
山东 ....

解决方案 »

  1.   

    select * from YourTable where charindex(col1,'山东青岛',1)
      

  2.   

    select col1 from tb where charindex(col1,'山东青岛')>0
      

  3.   

    --> 测试数据:[TB]
    if object_id('TB') is not null drop table TB
    create table TB([Name] varchar(4))
    insert into TB
    select '北方' union all
    select '东莞' union all
    select '福州' union all
    select '厦门' union all
    select '华中' union all
    select '南京' union all
    select '山东' union all
    select '上海' union all
    select '深圳' union all
    select '苏州' union all
    select '西南' union all
    select '粤西' union all
    select '中山' union all
    select '佛山' union all
    select '浙江'select * from [TB]DECLARE @var VARCHAR(10)
    SET @var = '山东青岛'
    SELECT * FROM TB WHERE [Name] = SUBSTRING(@var,0,3) 
      

  4.   

    --> 测试数据:[TB]
    if object_id('TB') is not null drop table TB
    create table TB([Name] varchar(4))
    insert into TB
    select '北方' union all
    select '东莞' union all
    select '福州' union all
    select '厦门' union all
    select '华中' union all
    select '南京' union all
    select '山东' union all
    select '上海' union all
    select '深圳' union all
    select '苏州' union all
    select '西南' union all
    select '粤西' union all
    select '中山' union all
    select '佛山' union all
    select '浙江'select * from [TB]DECLARE @var VARCHAR(10)
    SET @var = '山东青岛'
    SELECT * FROM TB WHERE CHARINDEX([Name],@var)>0
    /*
    山东
    */