帮我写个拼接字符串的函数吧,谢谢,不是简单的拼接啊,

xxmiaoyong126com 2010-07-02 01:04:09
nummtr=ubound(mtrarray(0,1),2)
能否通过1个函数,根据mtrarray数组有几个元素,就按照我下面的规则拼接处1个字符串sqlcus,
If nummtr=0 Then sqlcus=" t1.customer as cus1"
If nummtr=1 Then sqlcus=" isnull(t1.customer,"&mtrarray(0,1)&".customer) as cus1"
If nummtr=2 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,"&mtrarray(0,2)&".customer)) as cus1"
If nummtr=3 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,"&mtrarray(0,3)&".customer))) as cus1"
If nummtr=4 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,isnull("&mtrarray(0,3)&".customer,"&mtrarray(0,4)&".customer)))) as cus1"
If nummtr=5 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,isnull("&mtrarray(0,3)&".customer,isnull("&mtrarray(0,4)&".customer,"&mtrarray(0,5)&".customer))))) as cus1"
If nummtr=6 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,isnull("&mtrarray(0,3)&".customer,isnull("&mtrarray(0,4)&".customer,isnull("&mtrarray(0,5)&".customer,"&mtrarray(0,6)&".customer)))))) as cus1"

真的很急啊
...全文
52 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxmiaoyong126com 2010-07-02
谁能帮我写一个啊,
不胜感谢
回复
xxmiaoyong126com 2010-07-02
[Quote=引用 2 楼 shan1119 的回复:]

VB code
nummtr=ubound(mtrarray(0,1),2)

function getSql(nummtr as integer, mtrarray() as string) as string
dim p,flg

p="t1.customer"
flg=true
for i=0 to nummtr-1
if isnull(p……
[/Quote]

你好,感谢你的回帖,但是我的 isnull是字符串,
而不是真的要在程序里面去判断是否为null,
我仅仅在拼字符串
能否再看看,多谢
回复
shan1119 2010-07-02
nummtr=ubound(mtrarray(0,1),2)

function getSql(nummtr as integer, mtrarray() as string) as string
dim p,flg

p="t1.customer"
flg=true
for i=0 to nummtr-1
if isnull(p) and flg then
p=mtrarray(0,nummtr)
else
flg=false
end if
next
getSql= p & " as cus1"
end function

sqlcus=getSql(nummtr,mtrarray)
回复
xxmiaoyong126com 2010-07-02
If nummtr=0 Then sqlcus=" t1.customer as cus1"
If nummtr=1 Then sqlcus=" isnull(t1.customer,"&mtrarray(0,1)&".customer) as cus1"
If nummtr=2 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,"&mtrarray(0,2)&".customer)) as cus1"
If nummtr=3 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,
"&mtrarray(0,3)&".customer))) as cus1"
If nummtr=4 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,
isnull("&mtrarray(0,3)&".customer,"&mtrarray(0,4)&".customer)))) as cus1"
If nummtr=5 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,
isnull("&mtrarray(0,3)&".customer,isnull("&mtrarray(0,4)&".customer,"&mtrarray(0,5)&".customer))))) as cus1"
If nummtr=6 Then sqlcus=" isnull(t1.customer,isnull("&mtrarray(0,1)&".customer,isnull("&mtrarray(0,2)&".customer,
isnull("&mtrarray(0,3)&".customer,isnull("&mtrarray(0,4)&".customer,
isnull("&mtrarray(0,5)&".customer,"&mtrarray(0,6)&".customer)))))) as cus1"
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告