sql查询执行 [英] sql query execution

查看:115
本文介绍了sql查询执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须比较两个表的时间属性,查询就像

i have to compare time attributes of two tables and query is like

select s.sid
from sal s, prod p
where s.date=''2008-01-10''
and p.beginDate< s.date
and p.endDate>s.date



我想知道,它将如何评估.平均值,是否与以下查询相同



i want to know, how it will be evaluated.mean, is it same to following query

select s.sid
from sal s, prod p
where s.date=''2008-01-10''
and p.beginDate<2008-01-10''
and p.endDate>''2008-01-10''

推荐答案

使用SQL Server的查询分析器查找查询成本和性能.
Use Query analyzer of SQL Server to find the query cost and performance.


是的,它应该做同样的事情,但是您可以通过在SQL Server Management Studio Express中运行两个不同的查询版本来确定自己是什么.

Yes, it should do the same thing, but you could have determined that yourself by simply running the two different query versions in SQL Server Management Studio Express...



有两种比较日期时间类型的方法,但我看到您需要日期而不是时间比较功能?

好吧,如果您需要时间,请使用此函数CONVERT(DataType,Value,#)
这是一个例子
Hi,
there''s two way to compare Date Time types, but i see that you need the Date and not the time comparation right?

well, if you need the time Use this function CONVERT(DataType,Value,#)
here an example
SELECT CONVERT(varchar(11),fecha_de_Emision,113),
       CONVERT(varchar(11),fecha_de_Emision,112) ,
       CONVERT(varchar(11),fecha_de_Emision,110) ,
       CONVERT(varchar(11),fecha_de_Emision,109)
FROM TableOfSomeDates WHERE Date1 >=Date2



结果是几个日期格式不同..

请记住,如果要比较日期,请确保日期采用正确的格式,例如MM/DD/YYMM/DD/YYYYMM/DD/YYYY HH:MM:SS

简单的方法是使用CONVERT函数

CONVERT(varchar(11),fecha_de_Emision,110)结果为"11-09-2011"(避免时间,仅保留日期)
然后您可以将其与DateTime进行比较
问候!!!

代码包装在"pre"标签中[/编辑]



the result is a several dates in differents formats..

remember if you want comparate Date be sure that the date is in the correct format like MM/DD/YY OR MM/DD/YYYY OR MM/DD/YYYY HH:MM:SS

the simple way to do this is to use the CONVERT function

CONVERT(varchar(11),fecha_de_Emision,110) the result is ''11-09-2011'' (avoid the time, leave only the Date)
then you can compare with your DateTime
Regards!!!

Code is wrapped in "pre" tag[/Edited]


这篇关于sql查询执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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