今天遇到一个奇怪的问题,项目突然要从mysql切换到sql server数据库,包含order by 子句的嵌套子查询报错. 示例:select top 10 name,age,sex from ( select * from user order by id desc) temp; 在mysql数据库没有问题,但是sql server中报错: [Err] 42000 - [SQL Server]除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图.内联函数.派生表.
目前工作中遇到一个情况,需要将SQL Server中的一个字段提取拼音的首字母,字段由汉字.英文.数字以及“-”构成,百度了一堆,找到如下方法,记录一下,以备后用! 首先建立一个函数 --生成拼音首码 )) ) --WITH ENCRYPTION as begin declare @intLen int ) ) set @intLen = len(@str) set @strRet = '' begin set @temp = '' select @temp = case ) >= '帀' th
Expression构建DataTable to Entity 映射委托 1 namespace Echofool.Utility.Common { 2 using System; 3 using System.Collections.Generic; 4 using System.Data; 5 using System.Linq.Expressions; 6 using System.Reflection; 7 using System.Reflection.Emit; 8 9 publ
不多说了,说明后面是完整的代码,用来将字符串型的字段的各行的值拼成一个大字符串,也就是通常所说的Concat 例如有如下表dict ID NAME CATEGORY 1 RED COLOR 2 BLUE COLOR 3 APPLE FRUIT 4 ORANGE FRUIT 执行SQL语句:select category,dbo.concatenate(name) as names from dict group by category. 得到结果表如下 category
/* author OceanHo @ 2015-10-23 10:14:21 获取指定时间字符串指定日期的月最后一天日期 */ IF OBJECT_ID('get_LastDayDate') IS NOT NULL DROP FUNCTION get_LastDayDate GO )) RETURNS DATETIME AS BEGIN SELECT @dateString = DATEADD( /** 将参数3指定的时间加上参数2的天数 **/ DAY, /** 例如:@dateString
有时候需要对一个特定的含有小数点的数字保留指定位数,比如"123.123600". 在数据库中以函数的形式实现如下: USE [数据库名称] GO /****** Object: UserDefinedFunction [dbo].[AvgLimit] Script Date: 2016/12/29 11:30:44 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ,),@numlimit int) ) As Begin
1.创建存储过程: CREATE PROCEDURE proc_pr ---将create修改成alter可以修改存储过程: AS BEGIN IF EXISTS(SELECT * FROM sysobjects WHERE TYPE='U' AND NAME='te') BEGIN PRINT '存在要删除的表te'; DROP TABLE te; PRINT '已经删除表te'; END ELSE PRINT '不存在表te'; IF EXISTS(SELECT * FROM sysobje
每个地区递归层级可能不一致,数据表(table)存放最小层级地区 area --地区层级表 id name f_id leve 1 中国 0 1 2 湖北 1 2 3 武汉 2 3 ... --测试数据 with area(id,"name",f_id,leve) as ( ,, union all ,, union all ,, union all ,, union all ,, union all ,, union all ,, union all ,, union all ,,