December 14, 2008 at 6:25 pm
One approach is to create a parmaterized query, using the parameter to pass the user input (be sure to trim trailing blank characters from the user's input) to a dynamic SQL statement using the LIKE function. One caveat here, you are more than like going to get multiple rows returned, so you code must be able to handle that.
Something such as:
CREATE PROCEDURE Dbo.GetPatientInfo
@PatientId VARCHAR(50) -- this value is passed by the calling program
AS
DECLARE @sql AS VARCHAR(500)
SET @sql = 'SELECT Col1, Col2, Col3 -- replace Col1 with the actual column name
FROM your tables name
WHERE patentid LIKE (@PatientID)' + '%
EXECUTE @sql
I recommend that you refer to each link for full detailed discussions:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/2ef710bd-5504-4e50-aac4-371f4073cefa.htm
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a8d68d72-0f4d-4ecb-ae86-1235b962f646.htm
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/01c64ab0-9227-475a-a59a-ed80f9333042.htm
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/581fb289-29f9-412b-869c-18d33a9e93d5.htm
Viewing post 1 (of 2 total)
You must be logged in to reply to this topic. Login to reply