首页 新闻 会员 周边 捐助

存储过程中的这种写法是错误的,why?

0
悬赏园豆:10 [已解决问题] 解决于 2008-12-05 17:36

@CaseWeek int=(datepart(weekday,getdate())),

老是报错说: '(' 附近有语法错误   ,必须声明变量 '@CaseWeek'

问题补充: 这是整个过程代码: if exists(select * from sysobjects where xtype = 'P' and name ='HCase_Insert') drop procedure HCase_Insert go Create procedure HCase_Insert ( @PKID int output, @InputDate datetime=getdate, declare @CaseWeek int, set @CaseWeek=(datepart(weekday,getdate())), @CaseDate datetime , @Adr_numb nvarchar(20), @Case_type int , @Case_weather int, @Case_carType int, @Case_status int, @Road_type int, @Road_status int, @Road_form int, @Road_band int, @Summ_parties nvarchar(20), @Summ_units nvarchar(50), @Summ_carID nvarchar(20), @Casualty_death int, @Casualty_fleshwound int, @Casualty_GBH int, @Lose_road money, --路面损失 @Lose_safty money, --交通安全措施损失 @Lose_protection money, --安防损失 @Lose_virescence money, --绿化损失 @Lose_scutcheon money, --标牌损失 @Lose_chargesys money, --联网收费系统损失 @Lose_lights money, --照明设备损失 @Lose_total money, --合计 计算 可有计算机执行 @Handle_UnitID int ) As Insert into HCase(InputDate,CaseWeek,CaseDate,Adr_numb,Case_type,Case_weather,Case_carType, Case_status,Road_type,Road_status,Road_form,Road_band,Summ_parties,Summ_units, Summ_carID,Casualty_death,Casualty_fleshwound,Casualty_GBH,Lose_road,Lose_safty, Lose_protection,Lose_virescence,Lose_scutcheon,Lose_chargesys,Lose_lights,Lose_total) values(@InputDate,@CaseWeek,@CaseDate,@Adr_numb,@Case_type,@Case_weather,@Case_carType, @Case_status,@Road_type,@Road_status,@Road_form,@Road_band,@Summ_parties,@Summ_units, @Summ_carID,@Casualty_death,@Casualty_fleshwound,@Casualty_GBH,@Lose_road,@Lose_safty, @Lose_protection,@Lose_virescence,@Lose_scutcheon,@Lose_chargesys,@Lose_lights,@Lose_total) go
Longkin的主页 Longkin | 初学一级 | 园豆:3
提问于:2008-12-05 16:42
< >
分享
最佳答案
0

declare @CaseWeek int
set @CaseWeek = (datepart(weekday,getdate()))

在SQL 2008之前要用上面这种形式,到了2008可以写成一行:

declare @CaseWeek int = (datepart(weekday,getdate()))

不管哪种方式,一定先用declare声明

丁学 | 专家六级 |园豆:18730 | 2008-12-05 16:45
其他回答(1)
0

可以先声明一个变量放getdate()返回的日期,然后再使用此变量

declare @now datetime;

set @new = getdate();

declare @CaseWeek int
set @CaseWeek = (datepart(weekday,@now))

玉开 | 园豆:8822 (大侠五级) | 2008-12-05 17:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册