运行代码后为什么提示'go' 附近有语法错误。??
我把运行后的代码拷贝到查询分析器里可以运行的呀,好奇怪,为什么呢?? public DataSet GetNodeByID(decimal AID)
{
string sb = @"Create Function f_cid(@ID varchar(30)) returns @t_level table(id varchar(30) , level int)
as
begin
declare @level int
set @level = 1
insert into @t_level select @id , @level
while @@ROWCOUNT > 0
begin
set @level = @level + 1
insert into @t_level select a.id , @level
from sys_questiondir a , @t_Level b
where a.parentid = b.id and b.level = @level - 1
end
return
end";
sb+=@"
go
";
sb += "select a.* from Sys_questiondir a , f_cid(" + AID + ") b where a.id = b.id drop function f_cid ";
Siwei.LFCNET2.Data.Base bsql = new Siwei.LFCNET2.Data.Base();
DataSet ds = bsql.RunSQL2(sb.ToString(), null, "Sys_questiondir");
return ds;
}
我把运行后的代码拷贝到查询分析器里可以运行的呀,好奇怪,为什么呢?? public DataSet GetNodeByID(decimal AID)
{
string sb = @"Create Function f_cid(@ID varchar(30)) returns @t_level table(id varchar(30) , level int)
as
begin
declare @level int
set @level = 1
insert into @t_level select @id , @level
while @@ROWCOUNT > 0
begin
set @level = @level + 1
insert into @t_level select a.id , @level
from sys_questiondir a , @t_Level b
where a.parentid = b.id and b.level = @level - 1
end
return
end";
sb+=@"
go
";
sb += "select a.* from Sys_questiondir a , f_cid(" + AID + ") b where a.id = b.id drop function f_cid ";
Siwei.LFCNET2.Data.Base bsql = new Siwei.LFCNET2.Data.Base();
DataSet ds = bsql.RunSQL2(sb.ToString(), null, "Sys_questiondir");
return ds;
}
as
begin
declare @level int
set @level = 1
insert into @t_level select @id , @level
while @@ROWCOUNT > 0
begin
set @level = @level + 1
insert into @t_level select a.id , @level
from sys_questiondir a , @t_Level b
where a.parentid = b.id and b.level = @level - 1
end
return
end
go
select a.* from Sys_questiondir a , f_cid(382) b where a.id = b.id drop function f_cid
这是我调试的时候拷贝出来的SQL代码,在查询分析器运行没问题的呀
set @sql = "create .........................."
exec(@sql)
建函数的直接写sql server里
程序里写select 那句就行了