`
shanjing
  • 浏览: 54042 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

SqlServer中的Case When Like

阅读更多

数据库:SqlServer

--create table--
create table table1 (
    column1 nvarchar(200),
    column2 nvarchar(200)
);

--insert data--
insert into table1(column1,column2) values ('_abc_','aasf');
insert into table1(column1,column2) values ('_acbc_','aasf');
insert into table1(column1,column2) values ('23','ggg');
insert into table1(column1,column2) values ('_def_','aasf');
insert into table1(column1,column2) values ('asdf','3123');

--search as type--
Select
    type = case when column1 like '%_abc_%' then 'a'
                when column2 like '%GGG%' then 'b'
                when column1 like '%_def_%' then 'c'
            else 'others' end,
    column1,
    column2
from table1
where 1=1
分享到:
评论

相关推荐

    经典SQL语句大全

    在SQLServer中分组时:不能以text,ntext,image类型的字段作为分组依据 在selecte统计函数中的字段,不能和普通的字段放在一起; 13、对数据库进行操作: 分离数据库: sp_detach_db; 附加数据库:sp_attach_db 后...

    微软内部资料-SQL性能优化2

    Although 2 GB of address space may seem like a large amount of memory, application such as SQL Server could leverage more memory if it were available. The boot.ini option /3GB was created for those ...

    查询数据库状态

    if exists (select * from tempdb.sys.all_objects where name like '%#dbsize%') drop table #dbsize create table #dbsize (Dbname varchar(30),dbstatus varchar(20),Recovery_Model varchar(10) default ('NA'),...

    微软内部资料-SQL性能优化5

    If you build a clustered index without specifying the unique keyword, SQL Server forces uniqueness by adding a uniqueifier to the rows when necessary. This uniqueifier is a 4-byte value added as an ...

    经典全面的SQL语句大全

     SQL数据库:select case when len(field)>10 then left(field,10)+'...' else field end as news_name,news_id from tablename  Access数据库:SELECT iif(len(field)>2,left(field,2)+'...',field) FROM ...

    sql经典语句一部分

    在SQLServer中分组时:不能以text,ntext,image类型的字段作为分组依据 在selecte统计函数中的字段,不能和普通的字段放在一起; 13、对数据库进行操作: 分离数据库: sp_detach_db; 附加数据库:sp_attach_db 后...

    数据库操作语句大全(sql)

    在SQLServer中分组时:不能以text,ntext,image类型的字段作为分组依据 在selecte统计函数中的字段,不能和普通的字段放在一起; 13、对数据库进行操作: 分离数据库: sp_detach_db; 附加数据库:sp_attach_db ...

    超实用sql语句

    在SQLServer中分组时:不能以text,ntext,image类型的字段作为分组依据 在selecte统计函数中的字段,不能和普通的字段放在一起; 13、对数据库进行操作: 分离数据库: sp_detach_db; 附加数据库:sp_attach_db 后...

    SQL sever 实训

    SQL sever 2008 Rar! ?s X祕BwL0 17240671-1.sql ?年3月9日 --1.查询course表的所有信息(所有行所有列) USE Xk GO SELECT * FROM Course --有哪些种类的选修课?学分是多少 USE XK GO SELECT Kind,Credit FROM ...

    Sql for mysql

    5.8 The Case Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.9 The Scalar Expression Between Brackets . . . . . . . . . . . . . . . . 106 viii Contents 5.10 The Scalar...

    c#操作数据库,史上最牛逼的方法,你见过这种方法吗?

    SqlLamdalf.FactoryAnna factorySql = new SqlLamdalf.FactoryAnna(AnnaType.SqlServer, "Persist Security Info=False;Integrated Security=SSPI;Database=数据库名称;Server=sql服务器名称"); //对需要的表的...

    CE中文版-启点CE过NP中文.exe

    Added a "forgot scan" option (in case you forgot what you're doing) Pointerscan limit nodes is default on in a new ce install (remembers your choice when you disable it) Autoattach now happens using a...

    VB编程资源大全(英文源码 数据库)

    <END><br>34,DAOLike.zip This program Demonstrates how to use LIKE operator in Jet SQL Query (uses DAO).<END><br>35,xmlcreator.zip This project is a demonstration of how to convert a recordset ...

    经典小巧的表格组件 EhLib4.14

     can send SQL expressions on the server through the corresponding access engine.  It is TBDEDataDriverEh, TIBXDataDriverEh, TDBXDataDriverEh and TADODataDriverEh  component.  There are a ...

    EhLib-delphi

     can send SQL expressions on the server through the corresponding access engine.  It is TBDEDataDriverEh, TIBXDataDriverEh, TDBXDataDriverEh and TADODataDriverEh  component.  There are a ...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

     数据查询语言 (Data Query Language, DQL) 是SQL语言中,负责进行数据查询而不会对数据本身进行修改的语句,这是最基本的SQL语句。例如:SELECT(查询)  数据控制语言Data Controlling Language(DCL),用来...

    mysql数据库的基本操作语法

    MySQL中约束保存在information_schema数据库的table_constraints中,可以通过该表查询约束信息; 约束主要完成对数据的检验,保证数据库数据的完整性;如果有相互依赖数据,保证该数据不被删除。 常用五类约束: ...

    php.ini-development

    Directive names are *case sensitive* - foo=bar is different from FOO=bar. ; Directives are variables used to configure PHP or PHP extensions. ; There is no name validation. If ...

    cuteEditor6.0

    能自动清理HTML代码中Word标记 <br/>When text is pasted from Microsoft Word allot of unnecessary word specific markup is carried across. This can result in web pages that take an ...

    Beginning Python (2005).pdf

    Deciding When to Use DBM and When to Use a Relational Database 255 Working with Relational Databases 255 Writing SQL Statements 257 Defining Tables 259 Setting Up a Database 260 Try It Out: ...

Global site tag (gtag.js) - Google Analytics