CREATE procedure Up_Test
@births datetime
as
declare @test varchar(3000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,'''+CONVERT(varchar(10),births,120)+''',titles.pubdate)>1'
exec (@test)
GO
@births datetime
as
declare @test varchar(3000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,'''+CONVERT(varchar(10),births,120)+''',titles.pubdate)>1'
exec (@test)
GO
CREATE procedure Up_Test
@births datetime
as
declare @test varchar(3000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,CONVERT(varchar(10),@births,120),titles.pubdate)>1'
exec (@test)
GO
又出现下列的错误:
服务器: 消息 137,级别 15,状态 2,行 1
必须声明变量 '@births'。
我的@births是申明了datetime变量的嘛,为什么啊???
@births datetime
as
declare @test varchar(1000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,'+@births +' , titles.pubdate)>1'
exec( @test)
GOexec Up_Test '2001-3-22'
为什么会抱错:
从字符串转换为 datetime 时发生语法错误。
@births datetime
as
declare @test varchar(1000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,'+@births +' , titles.pubdate)>1'
exec( @test)
GO
CREATE procedure Up_Test
@births datetime
as
declare @test varchar(3000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,'''+CONVERT(varchar(10),@births,120)+''',titles.pubdate)>1'
execute (@test)
CREATE procedure Up_Test
@births datetime
as
declare @test varchar(3000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,CONVERT(varchar(10),@births,120),titles.pubdate)>1'
exec (@test)
GO
又出现下列的错误:
服务器: 消息 137,级别 15,状态 2,行 1
必须声明变量 '@births'。
我的@births是申明了datetime变量的嘛,为什么啊???
CREATE procedure Up_Test
@births datetime
as
declare @test nvarchar(3000),@par nvarchar(100)
select @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,CONVERT(varchar(10),@births,120),titles.pubdate)>1'
select @par='@births datetime'
execute sp_executesql @test,@par,@@births
CREATE procedure Up_Test
@births datetime
as
declare @test varchar(3000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,CONVERT(varchar(10),@births,120),titles.pubdate)>1'
exec (@test)
GO
又出现下列的错误:
服务器: 消息 137,级别 15,状态 2,行 1
必须声明变量 '@births'。
我的@births是申明了datetime变量的嘛,为什么啊???你的@births变量不能用‘’号引起来。
也就是:
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,CONVERT(varchar(10),@births,120),titles.pubdate)>1'
应改成:
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,'''+CONVERT(varchar(10),births,120)+''',titles.pubdate)>1'
CREATE procedure Up_Test
@births datetime
as
declare @test varchar(1000)
set @test='select * into test from titles,titleauthor where titles.title_id=titleauthor.title_id and datediff(d,'+@births +' , titles.pubdate)>1'
exec( @test)
GO