【SQL开源代码栏目提醒】:网学会员--在 SQL开源代码编辑为广大网友搜集整理了:26.sql绩等信息,祝愿广大网友取得需要的信息,参考学习。
use db_mr
sql--使用db_mrsql数据库
--使用DECLARE关键字声明4个变量
declare @timesj1 varchar(30),@timesj2 varchar(30),
@timenow varchar(30)
/*使用SET关键字为变量@timesj1和变量@timesj2分别
赋值为"2008/02/18"和"2008/04/02"*/
set @timesj1='2008/02/18'
set @timesj2='2008/04/02'
--使用SET关键字将当前时间赋给变量@timenow
set @timenow=(CONVERT(varchar(30),GETDATE(),111))
--使用IF判断变量@timesj1是否等于变量@timenow
if @timesj1<>@timenow
/*如果两个变量不相等,使用PRINT关键字输出
"@timesj1和@timenow两个时间不相同!"*/
print '@timesj1和@timenow两个时间不相同!'
else
/*如果两个变量相等,使用PRINT关键字输出
"@timesj1和@timenow两个时间相同!"*/
print '@timesj1和@timenow两个时间相同!'
--使用IF判断变量@timesj2是否等于变量@timenow
if @timesj2<>@timenow
/*如果两个变量不相等,使用PRINT关键字输出
"@timesj1和@timenow两个时间不相同!"*/
print '@timesj2和@timenow两个时间不相同!'
else
/*如果两个变量相等,使用PRINT关键字输出
"@timesj1和@timenow两个时间相同!"*/
print '@timesj2和@timenow两个时间相同!'