sql server 自定义split(分割)函数
ALTER function [dbo].[split]
(
@SourceSql varchar(8000),
@StrSeprate varchar(10)
)
returns @temp table(F1 varchar(100))
as
begin
declare @i int
set @SourceSql = rtrim(ltrim(@SourceSql))
set @i = charindex(@StrSeprate,@SourceSql)
while @i >= 1
begin
if len(left(@SourceSql,@i-1))>0
begin
insert @temp values(left(@SourceSql,@i-1))
end
set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)
end
if @SourceSql <> ''
insert @temp values(@SourceSql)
return
end
----------------------------------------
//应用
--开始迭代分割出来的参数
declare @str nvarchar(10)
declare auth_cur cursor for select F1 from split(要分割的参数,'分隔符')
open auth_cur
fetch next from auth_cur into @str
while ( @@fetch_status = 0 )
begin
//做处理
end
close auth_cur
deallocate auth_cur
相关文档:
数据库快照是MSSQL2005的新功能,仅在 Microsoft SQL Server 2005 Enterprise Edition 中可用。而且SQL Server Management Studio 不支持创建数据库快照,创建快照的唯一方式是使用 Transact-SQL。
数据库快照是数据库(称为“源数据库”)的只读静态视图。在创建时,每个数据库快照在事务上都与源数据库一致 ......
今天在登录sql2005的时候,想用sa的验证方式登录,发现登录不了,在网上查了下,按照下面的就可以解决。之前在装sql2005的时候,是设置成windows验证方式登录的。
具体解决方案如下:
1. 开启sql2005远程连接功能,开启办法如下,
配置工具->sql server外围应用配置器->服务和连接的 ......
编码过程中遇到的SQL分页情况,总结:
从数据库表中第M条记录开始检索N条记录
MySQL:
先查询分页,然后排序:
select * from (select * from student limit 5,2) pageTable order by id desc ;
先排序,然后查询分页:select * from student order by id desc limit 5,2 ;
Oracle:
SELECT * fro ......