晨风

-------------------- 业精于勤,荒于嬉;行成于思,毁于随

导航

随笔分类 -  SQL

摘要:SQL如何取出一个字符串中最后一个特殊字符右边的字符,例如:10*20*300,怎样得到300? 使用reverse配合charindex来实现。 reverse是把字符串倒置,然后通过charindex来获取倒置之后第一个*的位置,然后使用substring函数进行字符串截取,截取后再使用reve 阅读全文

posted @ 2018-01-18 13:59 shenyixin 阅读(2783) 评论(0) 推荐(0) 编辑

摘要:aa (1 行受影响) bb (1 行受影响) cc (1 行受影响) dd (1 行受影响) 阅读全文

posted @ 2017-03-05 16:28 shenyixin 阅读(198) 评论(0) 推荐(0) 编辑

摘要:SELECT CONVERT(VARCHAR(7),DATEADD(MONTH,number,'2016-01-01'),120) FROM master..spt_values WHERE type='P' AND DATEADD(MONTH,number,'2016-01-01')<='2017 阅读全文

posted @ 2016-05-27 16:31 shenyixin 阅读(2375) 评论(0) 推荐(0) 编辑

摘要:select convert(varchar(10),dateadd(dd,number,convert(varchar(8),getdate(),120)+'01'),120) as dt from master..spt_values where type='P' and dateadd(dd,number,convert(varchar(8),getdate(),120)+'01')<... 阅读全文

posted @ 2016-05-20 09:59 shenyixin 阅读(1985) 评论(0) 推荐(1) 编辑

摘要:WITH cte AS ( SELECT Id,Pid,DeptName,0 AS lvl FROM Department WHERE Id = 2 UNION all SELECT d.Id,d.Pid,d.DeptName,lvl+1 FROM cte c inner join Department d ON c.Pid = d.Id ) SELECT... 阅读全文

posted @ 2016-03-29 14:08 shenyixin 阅读(167) 评论(0) 推荐(0) 编辑

摘要:1.查询字段首位为汉字 2.查询字段包含汉字(任意位) 阅读全文

posted @ 2016-03-21 12:52 shenyixin 阅读(10620) 评论(0) 推荐(0) 编辑

摘要:1.Sql server自动生成拼音的函数 /* 根据汉字获取全拼 1.生成所有读音临时表 2.根据Chinese_PRC_CS_AS_KS_WS 排序获取读音 */ CREATE function f_GetPying(@str varchar(100)) returns varchar(8000 阅读全文

posted @ 2016-03-10 16:23 shenyixin 阅读(2842) 评论(0) 推荐(0) 编辑

摘要:select convert(varchar(7),dateadd(month,number,'2010-01-01'),120) from master..spt_values where type='P' and dateadd(month,number,'2010-01-01')<='2010 阅读全文

posted @ 2016-02-04 09:22 shenyixin 阅读(1839) 评论(0) 推荐(0) 编辑

摘要:convert(varchar(8000),cast(convert(float,'123456789') as decimal)) 阅读全文

posted @ 2015-03-24 12:19 shenyixin 阅读(287) 评论(0) 推荐(0) 编辑

摘要:--sql 2000select 序号 = (select count(1) from tb where 学号 < t.学号) + 1,学号 ,姓名 from tb t--sql 2005select 序号 = row_number() over(order by 学号),学号 ,姓名 from t... 阅读全文

posted @ 2015-01-04 15:48 shenyixin 阅读(8403) 评论(0) 推荐(0) 编辑

摘要:create table tb(id int, value varchar(10))insert into tb values(1, 'aa')insert into tb values(1, 'bb')insert into tb values(2, 'aaa')insert into tb va... 阅读全文

posted @ 2015-01-04 15:38 shenyixin 编辑

摘要:select right('00000'+ltrim(colname),5) from table 阅读全文

posted @ 2014-11-14 10:19 shenyixin 阅读(373) 评论(0) 推荐(0) 编辑

摘要:SELECT 行业名称FROM 评分标准GROUP BY 行业名称ORDER BY MAX(行业ID) DESC 阅读全文

posted @ 2014-10-10 09:58 shenyixin 阅读(635) 评论(0) 推荐(0) 编辑

摘要:GO不是标准SQL语句,甚至不是T-SQL语句。它只是SQL Server管理器(SSMS)中用来提交T-SQL语句的一个标志。你可以在SSMS中任意指定这个提交标志。SSMS->工具->选项->查询执行->SQL Server->批分隔符中指定这个提交标志。如下图: 除了提交外,GO还可以指定提交的次数。比如select * from tablego 2那么go之前的语句会被执行两次。如需转载,请注明本文原创自灰太狼的博客:http://blog.csdn.net/tjvictor 阅读全文

posted @ 2014-01-09 13:00 shenyixin 阅读(476) 评论(0) 推荐(0) 编辑

摘要:问题重现:--建表语句,测试数据 create table TestTable(Id int, Name nvarchar(20),CreateTime datetime) go declare @Count int = 1 while(@Count<1000) begin insert into TestTable select @Count,'Name '+CAST(@Count as nvarchar(10)),DATEADD(day,@Count,GETDATE()) set @Count = @Count+1; end go --建索引 create ... 阅读全文

posted @ 2014-01-09 12:59 shenyixin 阅读(710) 评论(0) 推荐(0) 编辑

摘要:select CONVERT(varchar, getdate(), 120 )2004-09-12 11:06:08select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')20040912110608select CONVERT(varchar(12) , getdate(), 23 )2008-04-01select CONVERT(varchar(12) , getdate( 阅读全文

posted @ 2013-12-23 10:21 shenyixin 阅读(1180) 评论(1) 推荐(0) 编辑

摘要:with Aas(select [科目ID] ,[父科目ID] ,[科目名称] ,[科目编号] ,[科目余额方向] ,[会计要素] ,[是否现金科目] ,[是否银行科目] ,[描述] ,[状态] ,[排序号] ,[科目属性ID] ,ROW_NUMBER() OVER(ORDER BY 科目编号 ASC) ROWNO from 财务接口_科目 where 会计要素='资产' ... 阅读全文

posted @ 2013-10-30 17:03 shenyixin 阅读(199) 评论(0) 推荐(0) 编辑

摘要:操作系统是Windows 8 64位,安装了Microsoft Office 2013,从SQL Server 2008中导入Excel文件时出现提示:未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序。(System.Data)解决办法:下载安装”2007 Office system 驱动程序:数据连接组件“:下载地址 阅读全文

posted @ 2013-09-22 16:46 shenyixin 阅读(6802) 评论(0) 推荐(1) 编辑

摘要:alter table a add num int identity 阅读全文

posted @ 2013-09-22 15:50 shenyixin 阅读(1029) 评论(0) 推荐(1) 编辑

摘要:package Sql;import java.sql.*;import java.util.logging.*;/** * SQL 基本操作 * 通过它,可以很轻松的使用 JDBC 来操纵数据库*/public class SQLHelper{ /** * 驱动 */ public static String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; /** * 连接字符串 */ public static String url = "jdbc:sqlserver... 阅读全文

posted @ 2013-05-23 10:16 shenyixin 阅读(261) 评论(0) 推荐(0) 编辑