SQL Server7.0与2000的语句转换问题,(100分)

  • 主题发起人 唐佐平
  • 开始时间

唐佐平

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是一个SQL Server7.0下的一个存储过程中的变量赋值语句,没问题,
************************************************************************************
set @sql=@sql+",(select count(*) from d_person
where deltype_no='"+@temp2+"' and
charindex(d_person.sec_no"+"+';','"+@temp1+"')>0 "+@date1+')'
************************************************************************************
〔说明:〕1、@sql、@temp1、@temp2、@date1为局部变量,定义如下:
declare @temp1 varchar(8000);
--记录了若干个员工工号,每个工号之间用“;”隔开,
declare @temp2 varchar(6);
--是从表中读出的一个离职类别号,
declare @sql varchar(8000);
--一串SQL查询语句,
declare @date1 varchar(100);--为存储过程的一个参数,传来的是一个条件,
2、表d_person为一个人事资料表,
deltype_no为员工离职类别编号,
sec_no为员工的工号,
请各位高手指教:
1、把那个存储过程移植到中,上面的赋值语句该怎么修改?
请加些说明。
2、SQL Server7.0下的SQL语句移植到SQL Server2000下,怎么移法?
要注意些什么?
3、先谢了!(您有什么要求都可以考虑)。
 

唐佐平

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位高手指点一下啊,分不够可以加啊!!
万分感谢!!!
 
Z

zm30

Unregistered / Unconfirmed
GUEST, unregistred user!
我想不用改就可以, 你有没有在SQLSERVER2000下试过,如果有错那错误信息是什么
 
H

htw

Unregistered / Unconfirmed
GUEST, unregistred user!
1.不用改 , 7.0和2000的存储过程可以通用的
2.用企业管理器的功能, 先在database上单击右键--所有任务--就找到你要的东东
可以将整个database倒出, 再在2000中用查询分析器执行sql文件即可, 可别忘记
执行create database, 这要看你在制作sql文件是怎么选择的了
 

唐佐平

Unregistered / Unconfirmed
GUEST, unregistred user!
问题是这个存储过程是在SQL Server7.0下写的,现在我用的是2000,在查询分析器中
执行有错误,我想可能是7.0和2000中单引号和双引号的使用不兼容的问题,我试着去
改了,但没有成功。
请大家帮帮忙,谢了!
 
D

dhl2001

Unregistered / Unconfirmed
GUEST, unregistred user!
把数据库的兼容级别改到7试一试
本质上还是字符串的问题
另外注意一下数据库转换过程中是否有字段属性被修改
 

唐佐平

Unregistered / Unconfirmed
GUEST, unregistred user!
改了兼容级别还是不行,
本来完整的存储过程如下:
--离职统计
/*---------------------------------------------------------------------------------*/
if exists (select name from sysobjects where lower(name)='person_del_01' and type='P')
drop procedure person_del_01;
go
create procedure person_del_01 @Dj int,@date1 varchar(100)
with encryption
as
begin
create table #ttt
(
sec_no varchar(10) not null,
sec_nm varchar(20) not null,
)
declare @temp varchar(6);
declare @temp2 varchar(6);
declare @sec_nm varchar(20);
declare @sql varchar(8000);
declare @temp1 varchar(8000);
declare BBB Cursor for select deltype_no from d_deltype order by deltype_no;
set @temp1=''
open BBB;
Fetch from BBB into @temp;
while @@Fetch_status=0
begin
set @sql='alter table #ttt add a'+@temp+'qty int'
exec(@sql)
Fetch from BBB into @temp;
end
declare ccc Cursor for Select Sec_no,sec_nm from P_Sec where Dj=@dj;
open ccc;
Fetch from ccc into @temp,@sec_nm;
while @@Fetch_status=0
begin
set @temp1='';
exec ExtractPSec @temp,@temp1 output;
set @sql=''
close bbb;
open bbb;
Fetch from BBB into @temp2;
while @@Fetch_status=0
begin
set @sql=@sql+",(select count(*) from d_person where deltype_no='"+@temp2+"' and charindex(d_person.sec_no"+"+';','"+@temp1+"')>0 "+@date1+')'
Fetch from BBB into @temp2;
end
set @sql="insert into #ttt select '"+@temp+"','"+@sec_nm+"'"+@sql
exec(@sql);
Fetch from ccc into @temp,@sec_nm;
end
close ccc;
deallocate ccc;
close BBB;
deallocate BBB;
select * from #ttt order by sec_no
end
go
/*----------------------------------------------------------------------------------------*/
在SQL Server2000中执行的错误消息如下:
/*----------------------------------------------------------------------------------------*/
服务器: 消息 207,级别 16,状态 3,过程 person_del_01,行 40
Invalid column name ',(select count(*) from d_person where deltype_no=''.
服务器: 消息 207,级别 16,状态 1,过程 person_del_01,行 40
Invalid column name '' and charindex(d_person.sec_no'.
服务器: 消息 207,级别 16,状态 1,过程 person_del_01,行 40
Invalid column name '+';',''.
服务器: 消息 207,级别 16,状态 1,过程 person_del_01,行 40
Invalid column name '')>0 '.
服务器: 消息 207,级别 16,状态 1,过程 person_del_01,行 43
Invalid column name 'insert into #ttt select ''.
服务器: 消息 207,级别 16,状态 1,过程 person_del_01,行 43
Invalid column name '',''.
服务器: 消息 207,级别 16,状态 1,过程 person_del_01,行 43
Invalid column name '''.
/*----------------------------------------------------------------------------------------*/
请赐教!!!
 
H

htw

Unregistered / Unconfirmed
GUEST, unregistred user!
还是你的40-43 的SQL语句有错, 你看, 系统将它们认成了字段名了。
请仔细检查
 

Unregistered / Unconfirmed
GUEST, unregistred user!
你看清楚错误了吗?查查你的列名是否正确了。
Invalid column name
 

唐佐平

Unregistered / Unconfirmed
GUEST, unregistred user!
我找到答案了,谢谢大家的关心。
 

唐佐平

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
942
SUNSTONE的Delphi笔记
S
S
回复
0
查看
760
SUNSTONE的Delphi笔记
S
I
回复
0
查看
397
import
I
顶部