工作中积攒的几个自定义SQL函数
工作中积攒的几个自定义SQL函数:
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: 字符串切割函数
-- =============================================
ALTER function [dbo].[Split]
(
@Text nvarchar(4000),
@Sign nvarchar(4000)
)
returns @tempTable table(id int identity(1,1) primary key,[value] nvarchar(4000))
AS
begin
declare @StartIndex int --开始查找的位置
declare @FindIndex int --找到的位置
declare @Content varchar(4000) --找到的值
set @StartIndex = 1
set @FindIndex=0
--遍历每个字符
while(@StartIndex <= len(@Text))
begin
SELECT @FindIndex = charindex(@Sign,@Text,@StartIndex)
--判断有没找到 没找到返回0
IF(@FindIndex =0 OR @FindIndex IS NULL)
begin
set @FindIndex = len(@Text)+1
end
set @Content = ltrim(rtrim(substring(@Text,@StartIndex,@FindIndex-@StartIndex)))
set @StartIndex = @FindIndex+1
insert into @tempTable ([value]) values (@Content)
end
return
end
-- ==========
相关文档:
Sql代码
--采用SQL语句实现sql2005和Excel 数据之间的数据导入导出,在网上找来一--下,实现方法是这样的:
--Excel---->SQL2005 导入:
select * into useinfo from O ......
http://www.umgr.com/blog/PostView.aspx?bpId=36294
1. 执行sql语句
int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callbacksql 语法
, void *, char **errmsg );
这就是执行一条 sql 语句的函数。
第1个参数不再说了,是前面open函数得到的指针。说了是关键数据结构。
第2个参数const char ......
//在应用程序Open 事件代码中
idle(600)
openbakflag=1
///////////////////////读取配置文件数据库连接设置///////////////////////
string server,datname,datuser,datpsw
server=ProfileString ( "yy.ini","yygl","server", "" )
datname=ProfileString ( "yy.ini","yygl","datname", "" )
datuser=ProfileStrin ......
SQL Server .NET Framework 数据提供程序 (SqlClient) 提供聚合函数。聚合函数对一组输入值执行计算并返回一个值。这些函数位于 SqlServer 命名空间中,该命名空间在您使用 SqlClient 时可用。提供程序的命名空间属性使实体框架可以确定此提供程序对特定构造(如类型和函数)使用哪个前缀。
下表显示 SqlClient 聚合函数。 ......
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [表 ......