|
5#
楼主 |
发表于 2002-11-23 21:25:00
|
只看该作者
哎呀,咋的了?咋的了?我咋眼冒金星有点晕呢。
好不容易看完了你的帖子,可感觉对我没多大的帮助(赶紧伸舌头),其实我要实现的东东就是把一行的不为0的字段作成一个记录集的一列。您交我的是在ACCESS中怎样作交叉查询,可我想通过SQL语句实现,小弟愚昧,不能举一反三,请再帮下忙。我自己做的东东和问题如下:
关于VB+ACCESS+SQL联合查询的问题
我有一个表有如下的字段:
ncellid \ncell1\ncell2\ncell3\ncell4......ncell25共26个字段,现我想把符合条件的某行(既ncellid为某值的行 )的ncell1\ncell2\ncell3\ncell4......ncell25的字段中不为空的字段作成记录集同一字段的不同行.,名字为cellid.例如我的符合条件的表的行的数据如下:
ncellid ncell1 ncell2 ncell3 ncell4......ncell25
20021 1 2 3 4 25
则查询的结果应为:
cellid ncellid
1` 20021
2 20021
3 20021
4 20021
..............
..............
25 20021
我用的方法如下有点笨,但目前想不出更好的来)
X$ = "select ncell1 as cellid ,ncellid from neighber where ncell1 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell2 ,ncellid from neighber where ncell2 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell3 ,ncellid as nee from neighber where ncell3 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell4 ,ncellid from neighber where ncell4 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell5 ,ncellid from neighber where ncell5 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell6 ,ncellid from neighber where ncell6 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell7 ,ncellid from neighber where ncell7 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell8 ,ncellid from neighber where ncell8 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell9 ,ncellid from neighber where ncell9 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell10 ,ncellid from neighber where ncell10 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell11 ,ncellid from neighber where ncell11 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell12 ,ncellid from neighber where ncell12 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell13 ,ncellid from neighber where ncell13 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell14 ,ncellid from neighber where ncell14 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell15 ,ncellid from neighber where ncell15 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell16 ,ncellid from neighber where ncell16 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell17 ,ncellid from neighber where ncell17 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell18 ,ncellid from neighber where ncell18 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell19 ,ncellid from neighber where ncell19 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell20 ,ncellid from neighber where ncell20 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell21 ,ncellid from neighber where ncell21 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell22 ,ncellid from neighber where ncell22 <> 0 and ncellid = "
X$ = X$ & scellid
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
X$ = X$ & " union select ncell23 ,ncellid from neighber where ncell23 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell24 ,ncellid from neighber where ncell24 <> 0 and ncellid = "
X$ = X$ & scellid
X$ = X$ & " union select ncell25 ,ncellid from neighber where ncell25 <> 0 and ncellid = "
X$ = X$ & scellid
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Set adjco = db.OpenRecordset(X$, dbOpenSnapshot)
当我去掉$$$之间的语句时程序正常,当加上后提示列别名错误。而我的后几条语句和前面的格式一样呀,是不是UNION查询最多允许22条语句呀?欢迎各位高手指点。如果不用这种方法还有 |
|