MS SQL Query以SQL为基础

时间:2022-06-27 11:32:41

I am looking to have the following query run on any database (right now it uses MSSQL):

我希望在任何数据库上运行以下查询(现在它使用MSSQL):

SELECT * FROM mytable 
WHERE 0<DATEDIFF(day, ISNULL(DateTwo, DateONE), getdate()) 
                               AND othercolumn != 'WUBAN'

Is there anyway to do this in a generic way?

无论如何以通用的方式做到这一点?

2 个解决方案

#1


2  

No, there is no generic way to do this.

If you support different DB engines you have to execute the proper SQL statement for each engine. Date functions differ on the individual DB engines and for this particular query there is no generic solution that works on all systems.

如果您支持不同的数据库引擎,则必须为每个引擎执行正确的SQL语句。日期函数在各个数据库引擎上有所不同,对于此特定查询,没有适用于所有系统的通用解决方案。

#2


1  

If DateTwo and DateOne are parameters, then you are able to do the following calculation in your application:

如果DateTwo和DateOne是参数,那么您可以在应用程序中执行以下计算:

DATEDIFF(day, ISNULL(DateTwo, DateONE), getdate())

and use the result in your query. If not, I can not see a way.

并在查询中使用结果。如果没有,我看不出办法。

#1


2  

No, there is no generic way to do this.

If you support different DB engines you have to execute the proper SQL statement for each engine. Date functions differ on the individual DB engines and for this particular query there is no generic solution that works on all systems.

如果您支持不同的数据库引擎,则必须为每个引擎执行正确的SQL语句。日期函数在各个数据库引擎上有所不同,对于此特定查询,没有适用于所有系统的通用解决方案。

#2


1  

If DateTwo and DateOne are parameters, then you are able to do the following calculation in your application:

如果DateTwo和DateOne是参数,那么您可以在应用程序中执行以下计算:

DATEDIFF(day, ISNULL(DateTwo, DateONE), getdate())

and use the result in your query. If not, I can not see a way.

并在查询中使用结果。如果没有,我看不出办法。