SQL Server 完美SPLIT函数
--
SQL Server Split函数
--
Author:zc_0101
--
说明:
--
支持分割符多字节
--
使用方法
--
Select * from DBO.F_SQLSERVER_SPLIT('1203401230105045','0')
--
select * from DBO.F_SQLSERVER_SPLIT('abc1234a12348991234','1234')
--
Select * from DBO.F_SQLSERVER_SPLIT('ABC',',')
CREATE
FUNCTION
F_SQLSERVER_SPLIT(
@Long_str
varchar
(
8000
),
@split_str
varchar
(
100
))
RETURNS
@tmp
TABLE
(
ID
inT
IDENTITY
PRIMARY
KEY
,
short_str
varchar
(
8000
)
)
AS
BEGIN
DECLARE
@long_str_Tmp
varchar
(
8000
),
@short_str
varchar
(
8000
),
@split_str_length
int
SET
@split_str_length
=
LEN
(
@split_str
)
IF
CHARINDEX
(
@split_str
,
@Long_str
)
=
1
SET
@long_str_Tmp
=
SUBSTRING
(
@Long_str
,
@split_str_length
+
1
,
LEN
(
@Long_str
)
-
@split_str_length
)
ELSE
SET
@long_str_Tmp
=
@Long_str
IF
CHARINDEX
(
REVERSE
(
@split_str
),
REVERSE
(
@long_str_Tmp
))
>
1
SET
@long_str_Tmp
=
@long_str_Tm
相关文档:
1. Q. What is a join?
A. Join is a process of retrieve pieces of data from different sets (tables) and returns them to the user or program as one joined collection of data.
2. Q. Can a table have more than one foreign key defined?
A. A table can have any number of foreig ......
写一个存储过程,将表一按照表二的形式进行查询。
仓库名称 商品名称 数量
A
S001 12
A S002 17
A
S003 10
B S001 21
B
S002 5
B S003 ......
今天我在SQL Server 2005中用脚本创建一张表,查资料发现有的脚本中字段有加[]中符号,我问了冬季,得知是这回事,用[]的字段名,即便是sql关键字也可以作为字段名,不会报错。
SQL Server里的表中添加一个字段,如:time系统会自动加一对方括号即:[time] ......
从博客园中看到一篇文章,介绍大软件公司面试时常常会出的两道SQL题(见附录)。
我觉得受益很多,在此之前,我一直觉得,SQL2008似乎提供了这方面的支持,但更低的版本,包括2005,非游标做不出来(水平够菜)。总结心得如下:
1、 强大的group by
1 select stdname,
2 isnull(sum( ......
很多时候我们可能都需要这么一个简繁互相转换的SQL函数,今天在网上找到的,收集下来。
以后有了它就省事多啦。不用再写程序取出来转换后再更新数据库了。
SQL简体繁体转换函数代码:
--生成码表
if exists (select * from dbo.sysobjects where id = object_id(N'[codetable]') and OBJECTPROPERTY(id, N'IsUserTable' ......