上面的问题找到了,谢谢大家
CREATE FUNCTION getTime
(@CurrentDate varchar(30))
RETURNS varchar(30)
AS
BEGIN
declare
@date varchar(30)
set @date='aa'
insert into test_aa values('127','11')
return @date
END
这个函数编译提示错误:在函数内不正确地使用了 'INSERT'。
请各位指点,谢谢
--过程1
CREATE procedure test_pro1
@a1 varchar(20),
@a2 int output
as
insert into test_bb values('124',98,96)
select @a2=count(*) from test_aa a,test_bb b where a.studentid=b.studentid
GO
--在这个过程中调用过程1
CREATE procedure test_pro2
@studentid varchar(20),
@CountNum int output
as
declare @aa int
declare @bb varchar(20)
--select @CountNum=count(*) from test_aa where studentid=@studentid
exec test_pro1(@bb,@aa)
GO
--例如,select top 10 title from article where class=1 order by id desc
--可以在函数中实现
create function f_str()
returns varchar(8000)
as
begin
declare @r varchar(8000)
set @r=''
select top 10 @r=@r+rtrim(title)
from article
where class=1
order by id desc
return(@r)
end
go
--调用
select dbo.f_str()
---下面是分页存储过程的例子
--邹建 2004.05--*/
create procedure p_splitpage
@sql nvarchar(4000),--要执行的sql语句
@currentpage int=2, --要显示的页码
@pagesize int=10,--每页的大小
@pagecount int=0 out--总页数
as
set nocount on
declare @p1 int
2、
--创建用户定义函数
create function f_Char2Binary(@str varchar(8000))
returns varchar(8000)
AS
BEGIN
DECLARE @r varbinary(8000),@i int,@j int
select @r=cast(@str as varbinary(8000)),@i=datalength(@r),@str=''
while @i>0
begin
select @j=substring(@r,@i,1),
@str=substring('0123456789ABCDEF',@j/16+1,1)
+substring('0123456789ABCDEF',@j%16+1,1)
+@str,
@i=@i-1
end
return(@str)
end
GO
--创建调用用户定义函数的存储过程
create procedure sp_test
as
select dbo.f_Char2Binary('asdfasfasf')
GO