易截截图软件、单文件、免安装、纯绿色、仅160KB

自定义多参数Sql聚合函数

Creating a CLR user define aggregate (part 2). Use multiple columns in the aggregation function
In part 1 we created a nice user defined aggregate. Now we are going to make it more sophisticated and let its value depend on two parameters ShipCountry and ShipShipCity. You might try having two parameters in Accumulate function of the aggregate but you will get an error
The Accumulate method in user defined aggregate "Bonus" must have exactly one parameter.
We are definitely looking into adding “multi-column aggregates” feature in the future versions of SQL Server. For now you can use a workaround. The idea is to create a worker UDT that contain all the fields required for the aggregation. So if you want to take Orders.ShipCountry and Orders.ShipCity into account the UDT should have two corresponding fields. You also need to create a user defined function that takes a number of parameters and returns an instance of the worker UDT. And finally you create an aggregate that takes the worker UDT as a parameter in its aggregation function.
Let’s say XYZ wants to consider German sales that has been shipped to Berlin as regular sales. To take ShipCity this into account you first need to create a UDT. I won’t implement several methods to keep the sample short.
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedType(Format.UserDefined, MaxByteSize=8000)]
public struct OrderData : INullable, IBinarySerialize
{
    public override string ToString()
    {
        throw new Exception("The method or operation is not implemented.");
    }
 
    public bool IsNull
    {
        get
        {
            return false;
        }
    }
 
 &n


相关文档:

SQLite不支持的SQL语法总结


1 TOP
这是一个大家经常问到的问题,例如在SQLSERVER中可以使用如下语句来取得记录集中的前十条记录:
SELECT TOP 10 * from [index] ORDER BY indexid DESC;
但是这条SQL语句在SQLite中是无法执行的,应该改为:
SELECT * from [index] ORDER BY indexid DESC limit 0,10;
其中limit 0,10表示从第0条记录开始,往后 ......

oracle 相關的sql語句

数据字典dict总是属于Oracle用户sys的。
  1、用户:
   select username from dba_users;
  改口令
   alter user spgroup identified by spgtest;
  2、表空间:
   select * from dba_data_files;
   select * from dba_tablespaces;//表空间
   select tablespace_name,sum(bytes), sum(b ......

清理SQL Server 2008数据库日志

清理SQL Server 2008数据库日志
收藏



第一步, 在收缩前先查看日志的大小:
SELECT

*
from
sysfiles
WHERE
name
LIKE
'
%
LOG
%'
GO
 
第二步, 把数据库的恢复模式设成”简单”:
ALTER

DATABASE
库名
SET
......

同步两个Sql server

--1:环境
  服务器环境:
  机器名称: ZehuaDb
  操作系统:Windows 2000 Server
  数据库版本:SQL 2000 Server 个人版
  客户端
  机器名称:Zlp
  操作系统:Windows 2000 Server
  数据库版本:SQL 2000 Server 个人版
  --2:建用户帐号
  在服务器端建立域用户帐号
  我的电脑管理- ......

SQL 查詢不區分大小寫

SQL 查詢不區分大小寫
2007年04月19日 星期四 15:27
正常用这个方法就给達到效果了。select * from
pl_account     where UPPER(fname) like 'PE%'
附加:
在sql2000和7.0的查询语句中,区分大写的查询方法
--sql2000,就用下面的方法.
--就是在字段名后加 collate Chi ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号