Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
It's not quite right
Message
De
30/01/2013 16:41:49
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01564725
Message ID:
01564737
Vues:
31
>What value do you want to set the @RecordExists variable when the record does not exist?

I'm good with the 1.

>
>I meant - do you know how to test SP in SSMS? Put a breakpoint in the SP body and use debug button in SSMS to run the procedure step by step.

Every time I try that, it runs the first two statements and then exits.

>
>
>>and 95% of the time there will NOT be an existing record, so if there is no record, it will be set to 1 - otherwise it's not 1 and when I execute the SP from SSMS, I get the expected results; if I run it from the app, I get nothing. This is the only SP that I have this problem with.
>>
>>And no, Naomi, I have no feathering clue how to test.
>>
>>
>>>>What's the difference?
>>>>
>>>>And no, I'm not trying to be snotty, I really am wondering what's the difference, other than you are, essentially, returning a true/false and I'm returning an integer
>>>>
>>>
>>>Your @RecExists will either be 1 if the record does not exist or will not be set at all if it does exist. In other words, right now it returns opposite meaning of what the name suggests and I believe it only returns result when record does not exist.
>>>
>>>BTW, do you know how to test the SP?
>>>
>>>>
>>>>>The first check should be
>>>>>
>>>>>select @RecExists = cast( case when exists (select 1 from TestResult where SCN = @SCN) then 1 else 0 end as bit)
>>>>>
>>>>>
>>>>>Also, I guess you want to declare this variable as bit if you only want to use it for test of existence.
>>>>>
>>>>>
>>>>>>Hi gang
>>>>>>
>>>>>>What I'm trying to do is create a stored procedure that will
>>>>>>
>>>>>>1) Check for existance of a record for a particular SCN
>>>>>>2) If it exists, check to see if this is a restarted test
>>>>>>
>>>>>>For whatever reason (which means I have no clue), the following SP runs with no error, but doesn't produce a result either.
>>>>>>
>>>>>>
>>>>>>USE [DLI_Testing]
>>>>>>GO
>>>>>>SET ANSI_NULLS ON
>>>>>>GO
>>>>>>SET QUOTED_IDENTIFIER ON
>>>>>>GO
>>>>>>
>>>>>>ALTER PROCEDURE [dbo].[TestStart] 
>>>>>>
>>>>>> @Subbank		nchar(1),
>>>>>> @SCN			Nchar(7),
>>>>>> @TCN			nchar(3),
>>>>>> @TestSection	nvarchar(1) OUTPUT,
>>>>>> @TestRestart	nvarChar(1) OUTPUT,
>>>>>> @ErrMsg		nvarChar(100) OUTPUT
>>>>>> 
>>>>>>AS
>>>>>>BEGIN
>>>>>>  declare @iError int, @iRowCnt int, @RecExists int, @TotQst int
>>>>>>  --SET NOCOUNT ON;
>>>>>>  select @RecExists = 1 where @SCN not in (select SCN from TestResult)
>>>>>>  if @RecExists = 1
>>>>>>    Begin
>>>>>>      begin transaction
>>>>>>      Insert into TestResult (Subbank,SCN,TCN)
>>>>>>        values('E0' + @Subbank, @SCN,@Tcn)
>>>>>>      select @iError = @@error, @iRowCnt = @@rowcount
>>>>>>      if @iError > 0 or @iRowCnt < 1
>>>>>>        begin
>>>>>>         Set @ErrMsg = 'Initial Insert Fails ' + @iError
>>>>>>         raiserror('Error on Initial Insert into Result -  %d',16,1, @iError) 
>>>>>>         rollback transaction
>>>>>>         Return
>>>>>>        end
>>>>>>      else
>>>>>>        commit transaction
>>>>>>        Select @TestSection = 'L', @TestRestart = 'F'
>>>>>>    end
>>>>>>  else	--Record already exists
>>>>>>    begin
>>>>>>      select @TestSection = 
>>>>>>        Case (ListenTotal + ReadTotal)
>>>>>>          when 25 then 'R'
>>>>>>          when 0 then 'L'
>>>>>>          when 50 then 'F'
>>>>>>        end,
>>>>>>        @TestRestart = 
>>>>>>          Case (ListenTotal + ReadTotal)
>>>>>>            when 25 then 'T'
>>>>>>            when 0 then 'F'
>>>>>>            when 50 then 'F'
>>>>>>          end
>>>>>>      from TestResult where SCN = @SCN
>>>>>>    end   
>>>>>>END
>>>>>>
>>>>>>
>>>>>>Have at it
>>>>>>Dorris
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform