随笔分类 -  SqlServer

摘要:sqlserver行转列 sqlserver列转行 阅读全文
posted @ 2016-07-01 00:11 蒹葭白露 阅读(5847) 评论(0) 推荐(1) 编辑
摘要:SqlServer2005以上版本提供了开窗排序和开窗聚集函数。 通过rank()和row_number()两个函数开窗排序。 rank()函数排列相同生成相同的排序,下一个不同排列排序将跳开,比如生成1 ,1,3。 row_number()函数即使排列相同也生成不同的排序,比如1,2,3。 ove 阅读全文
posted @ 2016-06-16 23:34 蒹葭白露 阅读(4188) 评论(0) 推荐(0) 编辑
摘要:declare @id int declare @name nvarchar(100) declare c_department cursor for select id,name from department open c_department fetch next from c_department into @id,@name while @@FETCH_STATUS=0 begin... 阅读全文
posted @ 2016-06-16 23:16 蒹葭白露 阅读(5262) 评论(0) 推荐(0) 编辑
摘要:GO --判断表是否存在方式1 if object_id(N'EF_User',N'U') is null --判断表是否存在方式2 --if not exists (select * from dbo.SysObjects WHERE id = object_id(N'[EF_User]') AND OBJECTPROPERTY(ID, 'IsTable') = 1) begin --直接创... 阅读全文
posted @ 2016-06-15 00:19 蒹葭白露 阅读(4392) 评论(0) 推荐(0) 编辑
摘要:--从table_name中随机取n行select top n * from table_name order by NEWID() 阅读全文
posted @ 2014-12-06 20:50 蒹葭白露 阅读(846) 评论(0) 推荐(0) 编辑
摘要:--返回字符表达式中最左侧字符的ASCII代码值select ASCII('a')--97select ASCII('A')--65select ASCII('aA')--97--将整数ASCII代码转换为字符select CHAR(97)--aselect CHAR(65)--Aselect CH... 阅读全文
posted @ 2014-11-15 17:41 蒹葭白露 阅读(15695) 评论(0) 推荐(1) 编辑
摘要:select @@IDENTITY --返回为当前会话的所有作用域中的任何表最后生成的标识值。select IDENT_CURRENT('table_name') --返回为任何会话和任何作用域中的特定表最后生成的标识值,它不受作用域和会话的限制,而受限于所指定的表select SCOPE_IDEN... 阅读全文
posted @ 2014-11-13 21:38 蒹葭白露 阅读(10510) 评论(0) 推荐(0) 编辑
摘要:set identity_insert 表名 ON --允许对自增列Id插入指定数据insert into table_name(Id,Name) values(1,'test')set identity_insert 表名 OFF --关闭对自增列Id插入指定数据注意:1.set identity... 阅读全文
posted @ 2014-11-12 20:33 蒹葭白露 阅读(49396) 评论(2) 推荐(2) 编辑
摘要:/*8 24 108 - hh:mm:ss */Select CONVERT(varchar(100), GETDATE(), 8)-- 19:34:00Select CONVERT(varchar(100), GETDATE(), 24)-- 19:34:00Select C... 阅读全文
posted @ 2014-11-12 19:59 蒹葭白露 阅读(636) 评论(0) 推荐(0) 编辑
摘要:1.数据环境准备 参考Oracle递归查询文章。2.查询某个节点下的所有子节点 with cte(id,name,parent_id) as ( select id,name,parent_id from SC_DISTRICT where name='巴中市' union all ... 阅读全文
posted @ 2014-10-17 00:00 蒹葭白露 阅读(542) 评论(0) 推荐(0) 编辑
摘要:1、“创建userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错”解决办法:删除 C:\Users\username\AppData\Local\Microsoft_Corporation\LandingPage.exe_StrongName_ryspccglaxmt4nhllj5z3thycltsvyyx\10.0.0.0\user.config 文件,AppData为隐藏目录。2、“以前版本的Microsoft Visual Studio 2008 失败”解决办法: 阅读全文
posted @ 2013-06-04 00:57 蒹葭白露 阅读(1197) 评论(0) 推荐(0) 编辑