Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored Procedure returning no results
Message
 
 
À
29/05/2012 17:18:34
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01544680
Message ID:
01544702
Vues:
20
>>>>What is the type of the field? Is it CHAR or varchar? As Boris showed, it doesn't work with char field.
>>>
>>>It is nvarchar
>>
>>Ok, what is your command which you printed and have you tried executing it?
>
>this is what gets printed:
>
>
SELECT [dbo].[Receipts].[PolicyHeaderFK],
>		[ReceiptAmount],
>		[ReceiptDate],
>		[ReceiptNumber],
>		[ReceiptPK],
>	    [ClientFK],
>		[PlanFK],
>		[PolicyNumber],
>		[PolicyPK],
>		[Code],
>		[Description],
>		[ClientNumber],
>		[CompanyName],
>		[FirstName],
>		[MiddleName],
>		[LastName]
>	FROM [dbo].[Receipts]
>		INNER JOIN [dbo].[Policyheaders] ON [dbo].[Receipts].[PolicyHeaderFK] = [PolicyHeaderPK]
>		INNER JOIN [dbo].[Policies]	ON [PolicyHeaderPK] = [dbo].[Policies].[PolicyHeaderFK]
>		INNER JOIN (SELECT [PolicyHeaderFK], MAX(EffectiveDate) as EffectiveDate 
>						FROM [dbo].[Policies]
>						GROUP BY [PolicyHeaderFK]) subquery ON [Policies].[PolicyHeaderFk] = subquery.policyHeaderFK AND Policies.EffectiveDate = subquery.EffectiveDate
>		inner join [dbo].[Plans] on [PlanFK] = [PlanPK]
>		inner join [dbo].[Clients] on [ClientFK] = [ClientPK] 
>WHERE 1 = 1
>   AND ([PolicyNumber] LIKE @PolicyNumber)
>   AND ([LastName] LIKE @ClientName OR [CompanyName] LIKE @ClientName)
>   AND [ReceiptNumber] LIKE @ReceiptNumber
>
>I added this to the top:
>
>
		declare @ReceiptNumber nvarchar(20)
>		set @ReceiptNumber = NULL
>		declare @ClientName nvarchar(20)
>		set @ClientName = NULL
>		declare @PolicyNumber nvarchar(20)
>		set @PolicyNumber = 'WLIF20120047'
>
>and when I run it I get no records

No wonder. Leave only PolicyNumber condition and re-test. The NULL parameters tests should not be there.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform