Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Return Value within user defined function

Author  Topic 

Rajeswari
Starting Member

20 Posts

Posted - 2001-12-04 : 01:06:55
I provided sample user defined function,

create function fn_test(@orgname varchar(200),@Renname varchar(200),
@Tempname varchar(200)) returns int as
begin
declare @cmdsql varchar(250)
declare @retval int
set @cmdsql = 'copy ' + @orgname + ' ' + @renname
exec @retval = exec master..xp_cmdshell @cmdsql
if (@retval = 0) -----------------111
begin
set @cmdsql = 'del ' + @orgname
exec @retval = exec master..xp_cmdshell @cmdsql
set @cmdsql = 'copy ' + @renname + '+' + @tempname + ' ' + @orgname
exec @retval = exec master..xp_cmdshell @cmdsql
end
else
begin
set @cmdsql = 'copy ' + @tempname + ' ' + @orgname
exec @retval = exec master..xp_cmdshell @cmdsql
end
return 0
end

if orginal file name not present in the directory, i will copy the content of temporary file to orginal file, otherwise i copy org. file to temp. file, delete the org. file, append 2 files and copy to original file. I will delete the temporary files created.

I am getting return value is always 1(See the code,in the place marked, -------111). If i copy the above statements in query analyser it is returning 0 if success, if i added to the function , it not works. What's the problem in the code.
   

- Advertisement -