[Solved] Where clause not filtering records in SQL Server

micah
 
on Mar 20, 2021 04:07 AM
811 Views

This very code supposed to fetch credits and deposits when customer phone number is searched, but the search is not working, when i click the button search without inserting any number records will still show am i missing something? 

The SQL Procedure is not selecting the right record, the select query supposed to check if the user’s phone number has any credit or deposit if yes then this credit and deposit record should be selected.

Stored ProceduresSET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[GetCustomerREPORTS]
	@Phone NVARCHAR(100)
AS
    SELECT * FROM ItemOrdered 
    WHERE [Status]='Credit' OR [Status]='Deposit' AND Phone=@Phone 
    ORDER BY Date_Sold DESC	
RETURN 0

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Mar 23, 2021 07:31 AM
micah says:
ALTER PROCEDURE [dbo].[GetCustomerREPORTS]
    @Phone NVARCHAR(100)
AS
SELECT * FROM ItemOrdered WHERE [Status]='Credit' OR [Status]='Deposit' AND Phone=@Phone
    ORDER BY Date_Sold DESC

Use below query.

ALTER PROCEDURE [dbo].[GetCustomerREPORTS]
    @Phone NVARCHAR(100)
AS
BEGIN
    SELECT * FROM ItemOrdered 
    WHERE ([Status]='Credit' OR [Status]='Deposit') AND Phone=@Phone
    ORDER BY Date_Sold DESC
END