create view viw_CurrentMonthLessonList
As Declare @Year int
Declare @Month int

Set @Year=datepart(yy,getdate())
Set @Month=datepart(mm,getdate())

select * from Lessons
where id>@Year*1000000+@Month*10000-----------------------------服务器: 消息 156,级别 15,状态 1,过程 viw_CurrentMonthLessonList,行 4
在关键字 'Declare' 附近有语法错误。
执行后提示语法错误,我对Sql不是很熟悉,烦请指点?

解决方案 »

  1.   

    是啊,view一般是为了方便查询指定一个表或几个表的部分字段,如非必要,where条件一般用得较少,可以在调用view时再加where
      

  2.   

    这样如何?
    create   view   viw_CurrentMonthLessonList 
    As select   *   from   Lessons 
    where   id> year(getdate())*1000000+month(getdate())*10000 
      

  3.   

    DECLARE里面不能出现在CREATE VIEW里面,可以先看看联机丛书