Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stored Procedure returning no results
Message
 
 
To
29/05/2012 17:18:34
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01544680
Message ID:
01544702
Views:
18
>>>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform