I am trying to create a Stored Procedure that will select the user's input using the LIKE command. Here is the Stored Procedure:
USE [Northwind] GO /****** Object: StoredProcedure [dbo].[CustOrderHist] Script Date: 01/16/2013 12:02:15 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[CustOrderHist] @CustomerID nchar(5) AS SELECT ProductName , C.CustomerID,Total=SUM(Quantity) FROM Products P, [Order Details] OD, Orders O, Customers C WHERE c.CustomerID LIKE @CustomerID + '%' AND C.CustomerID = O.CustomerID AND O.OrderID = OD.OrderID AND OD.ProductID = P.ProductID GROUP BY ProductName, c.CustomerID
The Stored Procedure will only return results on an exact match. Can someone please show me how to select the data by passing in a string and macthing using LIKE( or any other method)?
Change the parameter type to NVARCHAR(5) instead of NCHAR(5). Or if you are not able to change the function signature, cast it to NVARCHAR(5) in the stored procedure before using it in the like clause.