如何删除unnessary数据? [英] how to remove unnessary data?

查看:61
本文介绍了如何删除unnessary数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是sql sever的新手,我打算这样的查询

创建表studentinfo(id int,

xx int,

yy varchar(30),

zz int,

ww int,

uu datetime,

vv int,

ss varchar(30),

TT varchar(30),

kk int)



选择xx,yy,zz,ww,uu,vv,ss,TT,'''作为d1,'''作为d2,'''作为d3,'''作为d4来自studentinfo其中id =''1''和kk< =''0''

UNION

选择XX,yy,zz,ww,''''asd5, ''''为d6,'''为d7,'''为来自Studentinfo的d8,uu,vv,ss,TT,其中id =''1''和

kk> ''0'



这是显示这样的o / p:

xx yy zz ww d5 d6 d7 d8 d1 d2 d3 d4

1 jh 200 15 2013/01/1 2 ok fail 1900-01-01-00:00:00:00 0

1 jh 200 15 1900-01- 01-00:00:0 0:00 0 2013/01/1 2 ok failed

1 jh 200 15 1900-01-01-00:00:00:00 0 2013/01/1 2 ok failed



i想要从那个输出中删除1900-01-01-00:00:00:00 0。在我的表中我没有插入。但我就是那样.hepl我如何删除那个

Hi i am new to sql sever i worte a query like this
create table studentinfo (id int,
xx int,
yy varchar(30),
zz int,
ww int,
uu datetime,
vv int,
ss varchar(30),
TT varchar(30),
kk int)

select xx,yy,zz,ww,uu,vv,ss,TT,'''' as d1,'''' as d2,''''as d3,''''as d4 from studentinfo where id=''1''and kk<=''0''
UNION
select XX,yy,zz,ww,''''asd5,''''as d6,'''' as d7,''''as d8,uu,vv,ss,TT from Studentinfo where id=''1''and
kk >''0''

this is shows o/p like this :
xx yy zz ww d5 d6 d7 d8 d1 d2 d3 d4
1 jh 200 15 2013/01/1 2 ok fail 1900-01-01-00:00:00:00 0
1 jh 200 15 1900-01-01-00:00:00:00 0 2013/01/1 2 ok fail
1 jh 200 15 1900-01-01-00:00:00:00 0 2013/01/1 2 ok fail

i want to remove 1900-01-01-00:00:00:00 0 from that output .in table my table i am not inserted .but i was coming like that .hepl me how to remove that one

推荐答案

在你的工会中你有这样的字段:

xx,yy, zz,ww, uu ,... xx yy zz ww d5 ,... 分别。

现在: uu 属于datetime类型。但对于 d5 ,请选择''''(空字符串)。由于联合,空字符串被视为零,并且分别被视为日期时间,因此您获得日期时间的最小值:1900-01-01-00:00:00:00。

是按预期工作。

您有两种选择:

A)选择 NULL作为d5 而不是'''作为d5 ,并在演示时处理空值(在大多数情况下默认为空字符串)。

B)而不是 uu ,使用转换 [ ^ ]或演员表,例如: CONVERT(VARCHAR(24) ,uu),你可以保留空字符串,因为两者都是字符串。请注意,在2012版本以下的sql server中,只有很少的内置日期时间格式可以选择。
In your union you have fields like this:
xx,yy,zz,ww,uu,... and xx yy zz ww d5,... respectively.
Now: uu is of type datetime. But for d5 you select '''' (empty string). Because of the union the empty string is treated as zero, and as datetime respectively, thus you get the minimum value of datetime: 1900-01-01-00:00:00:00.
Is is working as expected.
You have two choices:
A) select NULL as d5 instead of '''' as d5, and handle null value at presentation time (will be empty string by default in most cases).
B) instead of uu, use convert[^] or cast, like this for example: CONVERT(VARCHAR(24),uu), and you can keep the empty string, since both will be strings. Be aware, that in sql server below version 2012 there are only few built-in datetime formats you can choose from.


这篇关于如何删除unnessary数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆