我有访问查询(2003):
SELECT [User] [100], [101], [102], [103], [104], [105], [106], [107], [108], [109], [110]
FROM [Access_Count>1]
结果我看起来像这样:
[User], [100], [101], [102], [103], [104], [105], [106], [107], [108], [109], [110]
UserA,100,101,,,,,,,,,
UserB,,,,,,,,109,110
有什么办法可以从输出中排除空白列/字段吗?所以我的结果会是这样的:
[User], [100], [101], [109], [110]
UserA,100,101,,
UserB,,,109,110
我今天通过谷歌进行了大规模的搜捕,在其他地方发现了一个类似的问题,但从未解决过。
干杯,
迈克尔
答案 0 :(得分:1)
输出必须是表吗?这些值可以连接成一个字符串吗?
如果是这样,您可以执行以下操作:
select t.[user],
mid((iif(Keep100 = 'Y', ','&[100])&
iif(Keep101 = 'Y', ','&[101])&
. . .
), 2)
from [AccessCount>1],
(select t, iif(max([100]) is null, 'N', 'Y') as Keep100,
iif(max([101]) is null, 'N', 'Y') as Keep101,
. . .
from [AccessCount>1]
) tkeep
我们的想法是使用逗号作为分隔符构建一个字符串。 mid
语句只删除字符串中的第一个字符。
答案 1 :(得分:0)
我不得不分成2个查询,当我试图完成所有200个查询时,它将#Reror列为#error。
非常感谢Gordon Linoff,我希望这有助于将来的某个人:)
select Access_Count_1.[Name],Access_Count_1.[Manager],
mid((iif(Keep100 = 'Y', ','&[100])&
iif(Keep101 = 'Y', ','&[101])&
iif(Keep102 = 'Y', ','&[102])&
iif(Keep103 = 'Y', ','&[103])&
iif(Keep104 = 'Y', ','&[104])&
iif(Keep105 = 'Y', ','&[105])&
iif(Keep106 = 'Y', ','&[106])&
iif(Keep107 = 'Y', ','&[107])&
iif(Keep108 = 'Y', ','&[108])&
iif(Keep109 = 'Y', ','&[109])&
iif(Keep110 = 'Y', ','&[110])&
iif(Keep111 = 'Y', ','&[111])&
iif(Keep112 = 'Y', ','&[112])&
iif(Keep113 = 'Y', ','&[113])&
iif(Keep114 = 'Y', ','&[114])&
iif(Keep115 = 'Y', ','&[115])&
iif(Keep116 = 'Y', ','&[116])&
iif(Keep117 = 'Y', ','&[117])&
iif(Keep118 = 'Y', ','&[118])&
iif(Keep119 = 'Y', ','&[119])&
iif(Keep120 = 'Y', ','&[120])&
iif(Keep121 = 'Y', ','&[121])&
iif(Keep122 = 'Y', ','&[122])&
iif(Keep123 = 'Y', ','&[123])&
iif(Keep124 = 'Y', ','&[124])&
iif(Keep125 = 'Y', ','&[125])&
iif(Keep126 = 'Y', ','&[126])&
iif(Keep127 = 'Y', ','&[127])&
iif(Keep128 = 'Y', ','&[128])&
iif(Keep129 = 'Y', ','&[129])&
iif(Keep130 = 'Y', ','&[130])&
iif(Keep131 = 'Y', ','&[131])&
iif(Keep132 = 'Y', ','&[132])&
iif(Keep133 = 'Y', ','&[133])&
iif(Keep134 = 'Y', ','&[134])&
iif(Keep135 = 'Y', ','&[135])&
iif(Keep136 = 'Y', ','&[136])&
iif(Keep137 = 'Y', ','&[137])&
iif(Keep138 = 'Y', ','&[138])&
iif(Keep139 = 'Y', ','&[139])&
iif(Keep140 = 'Y', ','&[140])&
iif(Keep141 = 'Y', ','&[141])&
iif(Keep142 = 'Y', ','&[142])&
iif(Keep143 = 'Y', ','&[143])&
iif(Keep144 = 'Y', ','&[144])&
iif(Keep145 = 'Y', ','&[145])&
iif(Keep146 = 'Y', ','&[146])&
iif(Keep147 = 'Y', ','&[147])&
iif(Keep148 = 'Y', ','&[148])&
iif(Keep149 = 'Y', ','&[149])&
iif(Keep150 = 'Y', ','&[150])
), 2) As Access
from [Access_Count_1],
(select
iif(max([100]) is null, 'N', 'Y') as Keep100,
iif(max([101]) is null, 'N', 'Y') as Keep101,
iif(max([102]) is null, 'N', 'Y') as Keep102,
iif(max([103]) is null, 'N', 'Y') as Keep103,
iif(max([104]) is null, 'N', 'Y') as Keep104,
iif(max([105]) is null, 'N', 'Y') as Keep105,
iif(max([106]) is null, 'N', 'Y') as Keep106,
iif(max([107]) is null, 'N', 'Y') as Keep107,
iif(max([108]) is null, 'N', 'Y') as Keep108,
iif(max([109]) is null, 'N', 'Y') as Keep109,
iif(max([110]) is null, 'N', 'Y') as Keep110,
iif(max([111]) is null, 'N', 'Y') as Keep111,
iif(max([112]) is null, 'N', 'Y') as Keep112,
iif(max([113]) is null, 'N', 'Y') as Keep113,
iif(max([114]) is null, 'N', 'Y') as Keep114,
iif(max([115]) is null, 'N', 'Y') as Keep115,
iif(max([116]) is null, 'N', 'Y') as Keep116,
iif(max([117]) is null, 'N', 'Y') as Keep117,
iif(max([118]) is null, 'N', 'Y') as Keep118,
iif(max([119]) is null, 'N', 'Y') as Keep119,
iif(max([120]) is null, 'N', 'Y') as Keep120,
iif(max([121]) is null, 'N', 'Y') as Keep121,
iif(max([122]) is null, 'N', 'Y') as Keep122,
iif(max([123]) is null, 'N', 'Y') as Keep123,
iif(max([124]) is null, 'N', 'Y') as Keep124,
iif(max([125]) is null, 'N', 'Y') as Keep125,
iif(max([126]) is null, 'N', 'Y') as Keep126,
iif(max([127]) is null, 'N', 'Y') as Keep127,
iif(max([128]) is null, 'N', 'Y') as Keep128,
iif(max([129]) is null, 'N', 'Y') as Keep129,
iif(max([130]) is null, 'N', 'Y') as Keep130,
iif(max([131]) is null, 'N', 'Y') as Keep131,
iif(max([132]) is null, 'N', 'Y') as Keep132,
iif(max([133]) is null, 'N', 'Y') as Keep133,
iif(max([134]) is null, 'N', 'Y') as Keep134,
iif(max([135]) is null, 'N', 'Y') as Keep135,
iif(max([136]) is null, 'N', 'Y') as Keep136,
iif(max([137]) is null, 'N', 'Y') as Keep137,
iif(max([138]) is null, 'N', 'Y') as Keep138,
iif(max([139]) is null, 'N', 'Y') as Keep139,
iif(max([140]) is null, 'N', 'Y') as Keep140,
iif(max([141]) is null, 'N', 'Y') as Keep141,
iif(max([142]) is null, 'N', 'Y') as Keep142,
iif(max([143]) is null, 'N', 'Y') as Keep143,
iif(max([144]) is null, 'N', 'Y') as Keep144,
iif(max([145]) is null, 'N', 'Y') as Keep145,
iif(max([146]) is null, 'N', 'Y') as Keep146,
iif(max([147]) is null, 'N', 'Y') as Keep147,
iif(max([148]) is null, 'N', 'Y') as Keep148,
iif(max([149]) is null, 'N', 'Y') as Keep149,
iif(max([150]) is null, 'N', 'Y') as Keep150
from [Access_Count_1]
) tkeep