ALTER PROCEDURE [dbo].[Proc_T_Novel_Topic_Add_ReCommand]
(
@BooksId int,
@UserId int,
@DateTime datetime,
@OrderType int
)
AS
declare @ID int
BEGIN
if (select count(*) from dbo.T_Books_Order where [email protected] and substring([DateTime],0,10)[email protected] and [DateTime] is not null)>0
begin
select 0 as id
end
else
begin
insert into dbo.T_Books_Order (UserId,OrderType,BooksId,[DateTime],Status)
values(@UserId,@OrderType,@BooksId,@DateTime,1)
select 1 as id
end
END
不对呀
我的意思就是 用一个已知的时间 去比较数据库里的时间 就想取 年月日 说以想截取 年月日 作比较 请大神们 指点迷津
------解决方案--------------------
- SQL code
ALTER PROCEDURE [dbo].[Proc_T_Novel_Topic_Add_ReCommand](@BooksId int,@UserId int,@DateTime datetime,@OrderType int)ASdeclare @ID intBEGIN if (select count(*) from dbo.T_Books_Order where [email protected] and CONVERT(VARCHAR(10),[DateTime],120)=CONVERT(VARCHAR(10),@DateTime,120) and [DateTime] is not null)>0beginselect 0 as idend else begin insert into dbo.T_Books_Order (UserId,OrderType,BooksId,[DateTime],Status) values(@UserId,@OrderType,@BooksId,@DateTime,1) select 1 as id endEND
------解决方案--------------------
- SQL code
convert(datetime,convert(varchar,[DateTime],112)) [email protected]
------解决方案--------------------
将日期转字符串可以这样
- SQL code
Select convert(varchar(10), getdate(), 121) --2012-08-07
------解决方案--------------------
- SQL code
if datediff(day,convert(varchar(10),dt1,120),dt2)=0 print '日期一样'else print '日期不一样'