PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > Stored Proc does not return any records when run as a whole
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Stored Proc does not return any records when run as a whole

Réponse
 
LinkBack Outils de la discussion
Vieux 21/05/2008, 17h40   #1
Saira
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Stored Proc does not return any records when run as a whole

Hi all - I have this sotored proc that when I test the seperate bits I get
the correct results, but when I run the whole thing i get nothing back.

Can anyone see where I am going wrong. s far as I can tell this should work.

ALTER PROCEDURE [dbo].[5D_CaseLetterGeneration]

(@LetterType varchar,

@LenderName varchar)

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;



declare @CaseID as varchar;



set @CaseID = (Select top (1) pre_CaseAndReportOrLetterID

from Filteredpre_ReportAndLetter

where statecode = 0 and fived_ReportSentToReportServer = 0

and pre_AccountAndReportorLetteridName = @LenderName and pre_LetterType =
@LetterType)

select * from [Reporting]

where CaseID = @CaseID;

SET NOCOUNT OFF

END

GO


  Réponse avec citation
Vieux 21/05/2008, 17h53   #2
Alejandro Mesa
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Stored Proc does not return any records when run as a whole

Saira,

You are omitting the len in the parameters and variable declaration. In this
case SQL Server will use 1.

Are those column VARCHAR(1)?

AMB


"Saira" wrote:

> Hi all - I have this sotored proc that when I test the seperate bits I get
> the correct results, but when I run the whole thing i get nothing back.
>
> Can anyone see where I am going wrong. s far as I can tell this should work.
>
> ALTER PROCEDURE [dbo].[5D_CaseLetterGeneration]
>
> (@LetterType varchar,
>
> @LenderName varchar)
>
> AS
>
> BEGIN
>
> -- SET NOCOUNT ON added to prevent extra result sets from
>
> -- interfering with SELECT statements.
>
> SET NOCOUNT ON;
>
>
>
> declare @CaseID as varchar;
>
>
>
> set @CaseID = (Select top (1) pre_CaseAndReportOrLetterID
>
> from Filteredpre_ReportAndLetter
>
> where statecode = 0 and fived_ReportSentToReportServer = 0
>
> and pre_AccountAndReportorLetteridName = @LenderName and pre_LetterType =
> @LetterType)
>
> select * from [Reporting]
>
> where CaseID = @CaseID;
>
> SET NOCOUNT OFF
>
> END
>
> GO
>
>
>

  Réponse avec citation
Vieux 21/05/2008, 17h58   #3
Aaron Bertrand [SQL Server MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stored Proc does not return any records when run as a whole

Did you try this?

USE tempdb;
GO

CREATE PROCEDURE dbo.Oops
@LetterType VARCHAR,
@LenderName VARCHAR
AS
BEGIN
SELECT @LetterType, @LenderName;
END
GO

EXEC dbo.Oops
@LetterType = 'blat splunge',
@LenderName = 'juan epstein';
GO

DROP PROCEDURE dbo.Oops;
GO




  Réponse avec citation
Vieux 21/05/2008, 18h06   #4
Alex Kuznetsov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Stored Proc does not return any records when run as a whole

On May 21, 10:40 am, "Saira" <sa...@5d.com> wrote:
> Hi all - I have this sotored proc that when I test the seperate bits I get
> the correct results, but when I run the whole thing i get nothing back.
>
> Can anyone see where I am going wrong. s far as I can tell this should work.
>
> ALTER PROCEDURE [dbo].[5D_CaseLetterGeneration]
>
> (@LetterType varchar,
>
> @LenderName varchar)
>
> AS
>
> BEGIN
>
> -- SET NOCOUNT ON added to prevent extra result sets from
>
> -- interfering with SELECT statements.
>
> SET NOCOUNT ON;
>
> declare @CaseID as varchar;
>
> set @CaseID = (Select top (1) pre_CaseAndReportOrLetterID
>
> from Filteredpre_ReportAndLetter
>
> where statecode = 0 and fived_ReportSentToReportServer = 0
>
> and pre_AccountAndReportorLetteridName = @LenderName and pre_LetterType =
> @LetterType)
>
> select * from [Reporting]
>
> where CaseID = @CaseID;
>
> SET NOCOUNT OFF
>
> END
>
> GO


In addition to Alejandro's and Aaron's replies, you use TOP(1) without
ORDER BY clause, which makes your results unpredictable.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h33.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12082 seconds with 12 queries