SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored procedure using the LIKE keyword
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

stevenandler
Starting Member

USA
42 Posts

Posted - 01/16/2013 :  12:08:46  Show Profile  Reply with Quote
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)?

Thank you.

James K
Flowing Fount of Yak Knowledge

3706 Posts

Posted - 01/16/2013 :  12:30:10  Show Profile  Reply with Quote
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.
Go to Top of Page

stevenandler
Starting Member

USA
42 Posts

Posted - 01/16/2013 :  13:14:07  Show Profile  Reply with Quote
That Worked!

Thank you James.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3706 Posts

Posted - 01/16/2013 :  14:02:31  Show Profile  Reply with Quote
You are welcome Steven - glad to be of help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000