注册 登录
编程论坛 SQL Server论坛

[求助]怎么去掉查询结果表中的空格?

aubblove 发布于 2007-08-20 17:13, 2540 次点击

这是我查询出来的语句,好多格包含null,我需要所有的null都删除,只保留有内容的格子,请问该怎么办??现在是这样的:

只有本站会员才能查看附件,请 登录
,要求成这样:

只有本站会员才能查看附件,请 登录

13 回复
#2
Kendy1234562007-08-20 17:15
你查询的语句和表的结构都不给出来 天知道怎么办
#3
xinzheng2007-08-20 17:26

晕,我看错了,照你这几个字段没法办到

[此贴子已经被作者于2007-8-20 17:28:16编辑过]

#4
aubblove2007-08-20 19:22
是这样的,我是把一个文本文件先导入SQL表里,只能导入一列,我通过下列语句得到表X1,这个表如果去掉所有的NULL表格就是我要的结果(上图2),能办到吗?
create table x1
(
题名 nvarchar(255) ,
作者 nvarchar(255) ,
单位 nvarchar(255) ,
)
insert into x1
select 题名=case
when substring(col001,10,3)='题名 'or substring(col001,9,3)='题名 'then substring(col001,12,254)
end ,
作者=case
when substring(col001,1,3)='作者 ' then substring(col001,4,254)
end ,
单位=case
when substring(col001,1,3)='单位' then substring(col001,4,254)
end
from 万方无清华

--万方无清华 代表我用文本文件导入的那个原表
#5
aubblove2007-08-20 19:26
各位帮帮忙啊!!多谢了!
#6
vsnet2007-08-20 21:51
严重冗余。。。。
感觉你的数据表怪怪的。
#7
aubblove2007-08-21 08:24

呵呵,是啊,所以才请教你们的啊!!

#8
aubblove2007-08-21 11:06

谢了各位.已经搞定!

#9
intelren2007-08-21 11:26
查询时候不需要左右连接,条件唯一即可
#10
xinzheng2007-08-21 18:29
回复
你在完整表的前面加一列id,id列为从1开始的数字
id
1
2
3
4
5
6
然后查询
select id,tm into #1 from aa
select id,zz into #2 from aa
select id,dw into #3 from aa
select a.tm,b.zz,c.dw into #4 from #1 a,#2 b,#3 c where a.id=b.id-1 and a.id=c.id-2
select * from #4 where tm<>''
drop table #1
drop table #2
drop table #3
drop table #4

[此贴子已经被作者于2007-8-21 18:32:07编辑过]

#11
toutou12312007-08-23 22:09

楼主 解决了 把语句贴出来啊 别就这样走撒 学习下

#12
aubblove2007-08-24 08:49
以下是引用xinzheng在2007-8-21 18:29:27的发言:
你在完整表的前面加一列id,id列为从1开始的数字
id
1
2
3
4
5
6
然后查询
select id,tm into #1 from aa
select id,zz into #2 from aa
select id,dw into #3 from aa
select a.tm,b.zz,c.dw into #4 from #1 a,#2 b,#3 c where a.id=b.id-1 and a.id=c.id-2
select * from #4 where tm<>''
drop table #1
drop table #2
drop table #3
drop table #4

用这种方法就可以解决,不过我换了查询方式,把"select 作者=case
when substring(col001,1,3)='作者 ' then substring(col001,4,254)
end
from 万方无清华下" 语句换成"select 作者=substring(col001,4,254)from 万方无清华下 where substring(col001,1,3)='作者 '"中间就不会有空格,省得想着怎么删掉他.

#13
wang_bo5122007-08-24 08:53
where条件中加一条,要的那个字段不为空,就可以了
#14
aubblove2007-08-24 11:55
楼上的兄弟姐妹们,谁能写一段脚本运行在按键精灵上面可以连接到某个网站自动下载一篇篇文章.

十分感谢!!!
1