易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

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 对xml类型的操作

 declare @XML XML
SET @XML='<root>
 <OLDVALUE>
  <H_Action id="1130">030</H_Action>
  <D_Action>030</D_Action>
  <OrderCompany>00220</OrderCompany>
  <OrderNumber>10004035</OrderNumber> ......

防止SQL注入攻击的注意事项

防止SQL注入攻击的注意事项
一. SQL Injection及其防范的基本知识
可能大家都知道,SQL注入主要是利用字符型参数输入的检查漏洞。
比如说,程序中有这样的查询:
 string sql = "SELECT * from SiteUsers WHERE UserName='" + userName + "'";
其中的userName参数是从用户界面上输入的。
如果是正常的输入,比如 ......

SQL行转列的动态构造方法

SQL行转列的动态构造方法
/*假设有张学生成绩表(tb)如下:
姓名 课程 分数
张三 语文 74
张三 数学 83
张三 物理 93
李四 语文 74
李四 数学 84
李四 物理 94
想变成(得到如下结果):
姓名 语文 数学 物理
---- ---- ---- ----
李四 74 84 94
张三 74 83 93
-------------------
*/
create t ......

sql 分割字符串 输出

示例:
传入多个Email地址,通过每个Email地址间的','分隔符,将各Email地址分开。
SELECT * from dbo.uf_Split('aa@aa.com,bb@bb.com,cc@cc.com,dd@dd.com',',');
查询结果:
subid      autoid
aa@aa.com 1
bb@bb.com 2
cc@cc.com 3
dd@dd.com 4
下面是[uf_Split]方法的具体实现:
CREATE   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号