编写存储过程:
查询点播资源,要求能按照资源类别名称、资源编号、资源名称、上载日期(区间)查询;
我的解答: CREATE PROCEDURE uer_select_v_sources @type_name varchar(15)='%',@source_id char(9)='%',@source_name varchar(50)='%',@up_date1 datetime='%',@up_date2 datetime='%'
ASselect a.source_id as 资源编号,a.source_name as 资源名称,a.source_price as 价格,a.up_date as 上载日期,b.type_name as 资源类别
from tsource as a,ttype as b
where a.type_id=b.type_id or b.type_name=@type_name or a.source_id=@source_id or a.source_name=@source_name or a.up_date between @up_date1 and @up_date2
GOexec uer_select_v_sources @type_name='动画片'有动画片这个类型啊,但是这样得不出结果,出现了‘服务器: 消息 241,级别 16,状态 1,过程 uer_select_v_sources,行 0
从字符串转换为 datetime 时发生语法错误。
’
我没有给@up_date1 datetime='%',@up_date2 datetime='%'这两个变量赋值,为什么还要出现这个语法错误啊
查询点播资源,要求能按照资源类别名称、资源编号、资源名称、上载日期(区间)查询;
我的解答: CREATE PROCEDURE uer_select_v_sources @type_name varchar(15)='%',@source_id char(9)='%',@source_name varchar(50)='%',@up_date1 datetime='%',@up_date2 datetime='%'
ASselect a.source_id as 资源编号,a.source_name as 资源名称,a.source_price as 价格,a.up_date as 上载日期,b.type_name as 资源类别
from tsource as a,ttype as b
where a.type_id=b.type_id or b.type_name=@type_name or a.source_id=@source_id or a.source_name=@source_name or a.up_date between @up_date1 and @up_date2
GOexec uer_select_v_sources @type_name='动画片'有动画片这个类型啊,但是这样得不出结果,出现了‘服务器: 消息 241,级别 16,状态 1,过程 uer_select_v_sources,行 0
从字符串转换为 datetime 时发生语法错误。
’
我没有给@up_date1 datetime='%',@up_date2 datetime='%'这两个变量赋值,为什么还要出现这个语法错误啊
解决方案 »
- 这句为什么出错:backup database catv to disk='C:\catv.bak'(详请进)
- 请问这个sql怎么写?数据为(年月,零售客户代码,购进量) 想得到的结果是(年月,当月购进>5且下月购进大于5的零售客户数量)谢谢
- 一个数据库的连接问题。请教,在线等。急
- 急问一个SQL 语句的写法!!!谢谢!
- .data文件如何使用?
- 可以用SQL SERVER来进行编程吗?
- 为何会显示‘记录集不可更新’?
- 一个oracle创建视图的sql,erro;ora-00905 missing keyword????
- 请问高手:Oracle PSQL中的Intersect在SQL200 TSQL中有相应的实现吗?
- 谁能推荐几本好书,不要初级的。
- 一个存储过程问题,高手进来帮帮忙
- 存储过程的默认值的问题 !! 非常简单
CREATE PROCEDURE uer_select_v_sources
@type_name varchar(15)='%',
@source_id char(9)='%',
@source_name varchar(50)='%',
@up_date1 datetime=null,
@up_date2 datetime=null
ASif @up_date1 is NULL and @up_date2 is NULL
select
a.source_id as 资源编号,
a.source_name as 资源名称,
a.source_price as 价格,
a.up_date as 上载日期,
b.[type_name] as 资源类别
from
tsource as a,
ttype as b
where
a.type_id=b.type_id or
b.[type_name]=@type_name or
a.source_id=@source_id or
a.source_name=@source_name
else
select
a.source_id as 资源编号,
a.source_name as 资源名称,
a.source_price as 价格,
a.up_date as 上载日期,
b.[type_name] as 资源类别
from
tsource as a,
ttype as b
where
a.type_id=b.type_id or
b.[type_name]=@type_name or
a.source_id=@source_id or
a.source_name=@source_name or
a.up_date between @up_date1 and @up_date2
GO
服务器: 消息 241,级别 16,状态 1,过程 uer_select_v_sources,行 0
从字符串转换为 datetime 时发生语法错误。
create table tsource(type_id varchar(10),source_id varchar(10),source_name varchar(10),source_price int,up_date datetime)
insert into tsource select '1','1','aa',11,'2004-01-01'
insert into tsource select '2','2','bb',22,'2005-01-01'create table ttype([type_name] varchar(10),type_id varchar(10))
insert into ttype select '动画片','1'
insert into ttype select 'hhhh','2'
goCREATE PROCEDURE uer_select_v_sources
@type_name varchar(15)='%',
@source_id char(9)='%',
@source_name varchar(50)='%',
@up_date1 datetime=null,
@up_date2 datetime=null
ASif @up_date1 is NULL and @up_date2 is NULL
select
a.source_id as 资源编号,
a.source_name as 资源名称,
a.source_price as 价格,
a.up_date as 上载日期,
b.[type_name] as 资源类别
from
tsource as a,
ttype as b
where
a.type_id=b.type_id and
(b.[type_name]=@type_name or
a.source_id=@source_id or
a.source_name=@source_name)
else
select
a.source_id as 资源编号,
a.source_name as 资源名称,
a.source_price as 价格,
a.up_date as 上载日期,
b.[type_name] as 资源类别
from
tsource as a,
ttype as b
where
a.type_id=b.type_id and
(b.[type_name] like @type_name or
a.source_id=@source_id or
a.source_name like @source_name or
a.up_date between @up_date1 and @up_date2)
GOexec uer_select_v_sources @type_name='动画片'exec uer_select_v_sources @type_name='动画片',@up_date1='2004-01-01',@up_date2='2005-01-01'
drop proc uer_select_v_sources
drop table tsource,ttype
@type_name varchar(15)='%',
@source_id char(9)='%',
@source_name varchar(50)='%',
@up_date1 datetime=null, ----改了
@up_date2 datetime=null ----改了
AS