Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Value within User defined function

Status
Not open for further replies.

Rajeswari

Technical User
Oct 6, 2001
17
IN
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top