Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2004, 08:57 AM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert statement is failing abruptly

Hi all,

My problem may sound very much weird to you but I hope anyone might have come across this.

I am executing a stored procedure inside a stored procedure. The code which I wish to execute is listed below.

CREATE procedure sp_save_placement_skills_new
@ActionId int,
@NewPlacementId int,
@UserId int
with recompile as
set implicit_transactions off
checkpoint

declare @tableSkillList table (skillName varchar(100) )
declare @tempSkill_ID int
declare @strPlacementSkillsUsed varchar(1000)
declare @strPlacementSkillsUsed_clone varchar(1000)
declare @IntPos int
declare @strSkillName varchar(50)

EXECUTE p_GetActionFieldValue @ActionId, @UserId, 'ContractConfigFields','PlacementSkillsUsed',
@strPlacementSkillsUsed OUTPUT

insert into test_skill_values values(@strPlacementSkillsUsed)


set @strPlacementSkillsUsed = @strPlacementSkillsUsed + ','

set @strPlacementSkillsUsed_clone = @strPlacementSkillsUsed
set @IntPos = CHARINDEX(',',@strPlacementSkillsUsed,1)

if replace(@strPlacementSkillsUsed_clone,',','') <> ''
begin
     while @IntPos > 0
            begin
        set @strSkillName = RTRIM(LTRIM(LEFT(@strPlacementSkillsUsed,@IntPos - 1)))
        Insert into @tableSkillList values(@strSkillName)
        Set @strPlacementSkillsUsed = RIGHT(@strPlacementSkillsUsed,LEN(@strPlacementSki llsUsed)-@IntPos)

        set @IntPos = CHARINDEX(',',@strPlacementSkillsUsed,1)

         end
end


DELETE FROM ContractSkill
WHERE ContractId = @NewPlacementid
    AND SkillId IN (SELECT Skillid
              FROM Skill
              WHERE SkillCategoryid IN
                (SELECT SkillCategoryid
                  FROM SkillCategory
                  WHERE Category = 'PlacementSkillsUsed'))

insert into contractskill select @NewPlacementId ,a.skillid,1 from skill a,@tableSkillList b
where upper(ltrim(rtrim(a.skill))) = upper(ltrim(rtrim(b.skillName))) and a.skillCategoryId IN (select SkillCategoryId from SkillCategory where Category = 'PlacementSkillsUsed')

GO

Basically what I am trying to do is that a comma delimited string is
being split and stored into table which has been created using table variable of sql server 2000. Then I put these values into actual table.

Problem Description
Some times whole of the stored procedure runs sucessfully without any problem at all. Sometimes it fails and is not able to put data into
contractskill table.

After using a debugging technique of putting messages while execution is in process in a table I find that
1) sometimes stored procedure execution terminates abruptly in while loop itself and after that no statement gets executed.
2)Sometimes it will split ok but fail during Delete statement.
3)Sometimes it will simply fail in last insert statement.

I have tried everything I can think of. I have tried recompile option,
setting implicit transactions off, using checkpoint, very thoroughly examined sql profiler to look for any error which I can understand for this abruput behaviour.


Reason I have tried implicit transactions off is due to the fact that
just before execution of this stored procedure set implicit transaction is on and after execution is set to off. But I thought that I would put first line in my stored procedure to set implicit transaction off so that I can take care of this statement.

Any help would be most welcome and thanks in advance. I have already spent too much time but still could not reach to any logical conclusion. By the way table test_skill_values is just being used for
storing messages during execution.


Thanks,
Puneet Mittal






Puneet
 
Old February 22nd, 2006, 04:07 AM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does anybody have a solution for this problem

 
Old February 22nd, 2006, 10:54 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Puneet,

Depending on the version of SQL Server you are using, you have several options. If you are using SQL Server 2000, i would look into using the RAISERROR statement in your stored procedure. Look in the BOL (Books Online) for this topic.

If you are using SQL Server 2005, you can use the new support TRY...CATCH statements to implement error handling.

Either of these will help you find out where the problem lies.

I hope this helps...

Scott






Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Statement Iashia06 Access 0 April 7th, 2006 12:45 PM
Insert into statement not working. alisonchase Access ASP 8 January 16th, 2005 10:52 AM
complex insert statement? qwjunk SQL Server 2000 3 November 2nd, 2004 04:12 AM
How do you execute a Insert statement? brendan82 Beginning VB 6 3 December 29th, 2003 12:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.