在SQL Server数据库中拆分字符串函数
SQL Server数据库中拆分字符串函数的具体方法:
以下为引用的内容:
CREATE FUNCTION uf_StrSplit '1.1.2.50','.'
(@origStr varchar(7000), --待拆分的字符串
@markStr varchar(100)) --拆分标记,如','
RETURNS @splittable table
(
str_id varchar(4000) NOT NULL, --编号ID
string varchar(2000) NOT NULL --拆分后的字符串
)
AS
BEGIN
declare @strlen int,@postion int,@start int,@sublen int,
@TEMPstr varchar(200),@TEMPid int
SELECT @strlen=LEN(@origStr),@start=1,@sublen=0,@postion=1,
@TEMPstr='',@TEMPid=0
if(RIGHT(@origStr,1)<>@markStr )
begin
set @origStr = @origStr + @markStr
end
WHILE((@postion<=@strlen) and (@postion !=0))
BEGIN
IF(CHARINDEX(@markStr,@origStr,@postion)!=0)
BEGIN
SET @sublen=CHARINDEX(@markStr,@origStr,@postion)-@postion;
END
ELSE
BEGIN
SET @sublen=@strlen-@postion+1;
END
IF(@postion<=@strlen)
BEGIN
SET @TEMPid=@TEMPid+1;
SET @TEMPstr=SUBSTRING(@origStr,@postion,@sublen);
INSERT INTO @splittable(str_id,string)
values(@TEMPid,@TEMPstr)
IF(CHARINDEX(@markStr,@origStr,@postion)!=0)
BEGIN
SET @postion=CHARINDEX(@markStr,@origStr,@postion)+1
END
ELSE
BEGIN
SET @postion=@postion+1
END
END
END
RETURN
END
例如:select * from uf_StrSplit('1,1,2,50',',')
输出结果:
以下为引用的内容:
str_id string
1 1
2 1
3 2
4 50
------分隔线----------------------------
相关文档:
1. 说明:复制表(只复制结构,源表名:a,新表名:b)
SQL: select * into b from a where 1<>1;
2. 说明:拷贝表(拷贝数据,源表名:a,目标表名:b)
SQL: insert into b(a, b, c) select d, e, f from b;
3. ......
1 :普通SQL语句可以用exec执行
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname from tab ......
有些时候我们需要查询数据库中的时间字段,例如2009-11-11 11:11:11:111 这样的时间格式。
而我们有些时候不用把整个的字段查询出来,需要把前面的日期截取出来,或者把后面的时间截取出来。
这个时候就要用到SQL里面的时间函数了:
select convert(char(10),字段名,108) from 表名
上述语句是将后面的时间查询出来,格 ......
做开发的过程中经常用到数据库远程连接的问题,有时候弄了半天也解决不了,这里根据我自己的一点经历对SQL Server远程连接问题做一总计。
首先这里主要说的是SQL Server 2005不是2000,因为2000有一些小的例外,例如安装sp4补丁等,这里不再讨论。事实上我 ......
SQL数据恢复软件 Log Explorer for SQL Server v4.0
log explorer使用的几个问题
1)对数据库做了完全 差异 和日志备份
备份时选用了删除事务日志中不活动的条目
再用Log explorer打试图看日志时
提示No log recorders found that match the filter,would you like to view unfiltered ......