|
很久了,论坛老师帮做的一个excel字符合并函数,现在由于采用SQL2000数据库和联网操作,目前不能运行了,请老师指教!
Function HeBing(ParamArray rArr()) As Variant
Dim i As Long
Dim sStr As String
For i = LBound(rArr(0), 1) To UBound(rArr(0), 1)
If rArr(0)(i, 1) = 0 Then
sStr = ""
Else
If rArr(0)(i, 1) <> "" And Not sStr Like "*" & rArr(0)(i, 1) & "*" Then sStr = sStr & rArr(0)(i, 1) & "/"
End If
Next i
If sStr = "" Then
HeBing = ""
Else
HeBing = Left(sStr, Len(sStr) - 1)
End If
End Function
这是汇总报表中的一列需要的数据,对数据库记录中不重复字符的合并。在SQL中不能使用了,我搜集了一个SQL的,能运行合并但是不能排除重复。
CREATE FUNCTION dbo.f_str(@col1 varchar(10))
RETURNS varchar(100)
AS
BEGIN
DECLARE @re varchar(100)
SET @re=''
SELECT @re=@re+','+CAST(b as varchar)
FROM tb
WHERE a=@col1
RETURN(STUFF(@re,1,1,''))
END
|
|