现有表 Term
结构如下
time1 time2 idterm
2009-2-15 2009-6-30 11
2009-9-10 2010-1-15 12
如果输入 2009-4-25 则应该取出idterm 11
如果输入 2009-12-5 则应该取出idterm 12
这个SQL该怎么写?
分少请见谅
SQL code:
select idterm from tb
where time1<=输入日期 and time2>=输入日期
SQL code:
declare @time datetime
set @time ='2009-4-25'
select top 1 * from term where time1<=@time and time2 >=@time
SQL code:
declare @time1 datetime,@time2 datetime
set @time1=..
set @time2=..
select idterm from tb where time between @time1 and @time2
case...when....then..
select idterm from tb
where time1 <=time2 and time2>=time1
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
将一个查询语句赋给一个变量,如下:
DECLARE @STR NVARCHAR(MAX)
SET @STR='SELECT * from SALE_PROD'
怎么样才能执行它呢?
请高手,仁兄,侠姐帮帮忙啊
多谢,可以啦,高手啊
直接执行就行了
exec ......
通过NAME字段条件查询一个数据表,假设我有100个姓名,有以下两个方法,
方法1:
把100个Name 组成一个SQL语句,比如 Select * from tmp_table where Name='张三' or Name ='李四' Or ...Or Name='第一百个姓名'
......
执行数据库操作时,直接用SQL 语句好一些 还是用存储过程更佳呢?
各抒起见
这个的具体问题具体分析
简单的select 、update和insert当然sql解决了
复杂的放在sql服务端应该好点
楼主请参阅
http://msdn.micr ......