存储过程往拼接的sql语句中传递日期值 declare @start datetime declare @end datetime set @start='2014-3-1' set @end='2014-3-31' ) set @sql=' select * from search_record where (Name!='' or Phone!='') and (thedate between @st and @en )' exec sp_executesql @sql,N'@st date
SQL语句获取数据库中的表主键,自增列,所有列 获取表主键 1:SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGEWHERE TABLE_NAME<>'dtproperties' 2:EXEC sp_pkeys @table_name='表名' 3: select o.name as 表名,c.name as 字段名,k.colid as 字段序号,k.keyno as 索引顺序,t.name as
话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int()类型的,现需要查询今天添加的文章总数并且按照时间从大到小排序,则查询语句如下: select * from `article` where date_format(from_UNIXTIME(`add_time`),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d'); 或者: select * from `article` where to_days(date_fo
在SQL Server 里的日期数据,我们经常可以用 字段<='2008-5-20'这样的表达式,但在oracle却不可以,因为数据类型不一样 字段是date型,'2008-5-20'是字符型,需要用to_char 或者to_number转换成相同的类型才能进行比较.刚开始这让我觉得不习惯,觉得不好,不过时间长了,觉得也有不少便利之处,尤其是配合trunc啊,to_char之类的,下面简单写一下常用的一些对日期的操作 获取当前的系统时间:select sysdate from dual
下面的sql语句可以查看表的信息.其中modify_date和create_date可以根据表的修改时间来查看.如果不需要删除后,就能看到所有表的字段信息 ) PERCENT d.name AS 表名, ISNULL(f.value, '') AS 表说明, a.name AS 字段名, CASE WHEN EXISTS ( FROM sysobjects WHERE xtype = 'PK' AND name IN (SELECT name FROM sysindexes WHERE indi
本周:select * from table where datediff(week,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段本月:select * from table where datediff(Month,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段本季:select * from table where datediff(qq,C_CALLTIME,getdate())=0 求以下日期SQL
用sql获取数据库中所有的表名的方法:1.oracle下:select table_name from all_tables;2.MySQL下:select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';3.sql server下:select name from sys.tables go
有如下表数据: 获取“菜单”分类的子分类数据列表: SELECT a.cat_id, a.cat_name, a.sort_order AS parent_order, a.cat_id, b.cat_id AS child_id, b.cat_name AS child_nameFROM article_cat AS a JOIN article_cat AS b ON b.parent_id = a.cat_id ORDER BY parent_order ASC, a.cat_id ASC