c# 从数据库中取数据 时间段内 数据库中日期是文本类型
visualstudio2008平台access数据库,用SQL语句查询所规定的时间该怎么写呢?比如表名是Chart,数据字段名是Date,所存储的数据是文本类型的年月日...
visual studio 2008平台access数据库,用SQL语句查询所规定的时间该怎么写呢?
比如表名是Chart,数据字段名是Date,所存储的数据是文本类型的年月日时如:2010020301,我的时间对话框中输入的是时间类型如“2010年02月03日01:05的时间1,另外一个输入的是时间2,我只要查询指定的两个时间对话框间年月日时时间段范围的数据,该怎么写SQL语句?请详细点,谢谢 展开
比如表名是Chart,数据字段名是Date,所存储的数据是文本类型的年月日时如:2010020301,我的时间对话框中输入的是时间类型如“2010年02月03日01:05的时间1,另外一个输入的是时间2,我只要查询指定的两个时间对话框间年月日时时间段范围的数据,该怎么写SQL语句?请详细点,谢谢 展开
展开全部
朋友,因为对ACCESS不是非常清楚其数据类型,我暂时用SQL中的方式帮你解决此问题:
先创建表:
/****** Object: Table [dbo].[Chart] Script Date: 09/30/2010 12:39:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Chart](
[id] [int] IDENTITY(1,1) NOT NULL,
[employee] [varchar](50) NULL,
[Date] [varchar](50) NULL,
CONSTRAINT [PK_Chart_1] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: StoredProcedure [dbo].[procGetInfoByDate] Script Date: 09/30/2010 12:39:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[procGetInfoByDate]
@beginDate varchar(5),
@endDate varchar(5)
as
begin
select * from Chart where Chart.[Date] between convert(varchar(50),'201002030'+@beginDate) and
convert(varchar(50),'201002030'+@endDate)
end
GO
方法一:直接写SQL语句:
select * from Chart where Chart.[Date] between convert(varchar(50),'201002030'+'1') and
convert(varchar(50),'201002030'+'2')
方法二:用存储过程,这种方法更适合你的需求
create proc procGetInfoByDate
@beginDate varchar(5),
@endDate varchar(5)
as
begin
select * from Chart where Chart.[Date] between convert(varchar(50),'201002030'+@beginDate) and
convert(varchar(50),'201002030'+@endDate)
end
调用存储过程:
procGetInfoByDate 1,2
希望能为你提供借鉴!
先创建表:
/****** Object: Table [dbo].[Chart] Script Date: 09/30/2010 12:39:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Chart](
[id] [int] IDENTITY(1,1) NOT NULL,
[employee] [varchar](50) NULL,
[Date] [varchar](50) NULL,
CONSTRAINT [PK_Chart_1] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: StoredProcedure [dbo].[procGetInfoByDate] Script Date: 09/30/2010 12:39:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[procGetInfoByDate]
@beginDate varchar(5),
@endDate varchar(5)
as
begin
select * from Chart where Chart.[Date] between convert(varchar(50),'201002030'+@beginDate) and
convert(varchar(50),'201002030'+@endDate)
end
GO
方法一:直接写SQL语句:
select * from Chart where Chart.[Date] between convert(varchar(50),'201002030'+'1') and
convert(varchar(50),'201002030'+'2')
方法二:用存储过程,这种方法更适合你的需求
create proc procGetInfoByDate
@beginDate varchar(5),
@endDate varchar(5)
as
begin
select * from Chart where Chart.[Date] between convert(varchar(50),'201002030'+@beginDate) and
convert(varchar(50),'201002030'+@endDate)
end
调用存储过程:
procGetInfoByDate 1,2
希望能为你提供借鉴!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询