|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Friday, April 12, 2013 12:27 PM
Points: 416,
Visits: 542
|
|
I wish to allow the user to load in from a control the search input for the wildcard search in a SELECT query in a TSQL stored procedure.
MyStoredProc( @SearchContains VARCHAR(20)=NULL, @SearchStartsWith VARCHAR(20)=NULL)
NOTE: Field 'OrderName' is a VARCHAR field
SELECT OrderID, OrderName, OrderValue FROM <table> WHERE OrderName = @SearchContains
or
SELECT OrderID, OrderName FROM <table> WHERE OrderName = @SearchStartsWith
I wish for the @SearchStartsWith (or @SearchContains) to be the input to go in between the wild card parameters of WHERE clause search, but I dont know the parameters to get the job done in the two search examples above, please advise, thanks
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 5:35 PM
Points: 5,722,
Visits: 6,194
|
|
MyStoredProc( @SearchContains VARCHAR(20)=NULL, @SearchStartsWith VARCHAR(20)=NULL)
NOTE: Field 'OrderName' is a VARCHAR field
SELECT OrderID, OrderName, OrderValue FROM <table> WHERE OrderName like '%' + @SearchContains + '%'
or
SELECT OrderID, OrderName FROM <table> WHERE OrderName like @SearchStartsWith + '%'
or SELECT OrderID, OrderName FROM <table> WHERE LEFT( OrderName, LEN(@SearchStartsWith)) = @SearchStartsWith
- Craig Farrell
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions | Forum Netiquette For index/tuning help, follow these directions. |Tally Tables Twitter: @AnyWayDBA
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
Craig Farrell (9/2/2010)
SELECT OrderID, OrderName FROM <table> WHERE LEFT( OrderName, LEN(@SearchStartsWith)) = @SearchStartsWith this is bad from performance perspective , never use function with where caluse column , it will force sql optimizer to NOT TO use index
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Friday, April 12, 2013 12:27 PM
Points: 416,
Visits: 542
|
|
Roger that !, Thanks !
|
|
|
|