在student数据库中有表student,字段是 sno,sname,sex,where,birthday,
我在查询分析器里面写如下代码:
use student
declare @LastName char(2)
@CityVariable char(2)
@BirthdayVariable datetime
set @LastName='杨'
set @CityVariable='唐'
set @BirthdayVariable='1983-9-11'select sno 学号,sname 姓名,sex 性别,wherefrom 生源,birthday 生日
from student
where sno like @LastName+'%'and wherefrom like '%'+@CityVariable+'%' and birthday=@Birthday为什么总是错误呢?
我在查询分析器里面写如下代码:
use student
declare @LastName char(2)
@CityVariable char(2)
@BirthdayVariable datetime
set @LastName='杨'
set @CityVariable='唐'
set @BirthdayVariable='1983-9-11'select sno 学号,sname 姓名,sex 性别,wherefrom 生源,birthday 生日
from student
where sno like @LastName+'%'and wherefrom like '%'+@CityVariable+'%' and birthday=@Birthday为什么总是错误呢?
@CityVariable char(2),
@BirthdayVariable datetime
set @LastName='杨'
set @CityVariable='唐'
set @BirthdayVariable='1983-9-11'select sno,sname,sex,wherefrom,birthday
from student
where sno like @LastName+'%'and wherefrom like '%'+@CityVariable+'%' and birthday=@BirthdayVariable
@CityVariable char(2),
@BirthdayVariable datetime
set @LastName='杨'
set @CityVariable='唐'
set @BirthdayVariable='1983-9-11'select sno 学号,sname 姓名,sex 性别,wherefrom 生源,birthday 生日
from student
where sno like @LastName+'%'and wherefrom like '%'+@CityVariable+'%' and birthday=@BirthdayVariable --未定义变量@Birthday
那@BirthdayVariable的实际时间值就变成了'1983-09-11 00:00:00.0'declare @LastName char(2), --定义变量
@CityVariable char(2),
@BirthdayVariable datetime
set @LastName='杨'
set @CityVariable='唐'
set @BirthdayVariable='1983-9-11'select sno 学号,sname 姓名,sex 性别,wherefrom 生源,birthday 生日
from student
where sno like @LastName+'%'and wherefrom like '%'+@CityVariable+'%' and birthday
between @BirthdayVariable and dateadd(dd,1,@BirthdayVariable) --这里换一下试试