Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stored Procedure returning no results
Message
From
30/05/2012 07:16:07
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01544680
Message ID:
01544751
Views:
22
>>>>>>>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.
>>
>>My head is not getting around this. It's been a long day so I'm shutting off for now and will check back tomorrow and see if this makes more sense.
>
>In your test remove 2 last conditions and only test where PolicyNumber like @PolicyNumber
>
>If this works correctly, then verify your query string again.

Hi Naomi,

I removed the last two lines from the WHERE clause and ran it again and I don't get any results returned.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform