![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi Paparush, I believe the problem is because you're mixing up dynamic SQL with static SQL. The @SearchTerm variable that you are building up can not be used to specify additional LIKE criteria for the Subject column, each LIKE condition needs to be individually coded into your static SQL. The alternative is to build the entire SELECT as dynamic SQL. This provides additional flexibility, but there are performance and security implications when doing this (google SQL injection). Good luck! J |
#4
| |||
| |||
|
|
I'm relatively new to calling stored procedures, and I have a question about passing in a parameter. Very simple search proc that is called to search terms submitted by the user. I've just copied the relevant portion here.. IF @SearchCriteria = 2 BEGIN declare @SearchTerm varchar(8000) set @SearchTerm = char(39)+'%foo%'+ char(39) + ' AND SUBJECT LIKE ' + char(39) + '%bar%'+char(39) |
|
SELECT * FROM CM_Case WHERE Subject LIKE @SearchTerm ORDER BY CaseNo END; So basically, the user might submit one term, or multiple terms. When they submit mulitple terms, my code builds the @SearchTerm as described above. However, this code always returns zero results. |
|
If I copy out the @SearchTerm string and run it through Query Analyzer, it runs fine and returns a result set. What is the Stored Proc doing behind the scenes that makes this simple query fail when the search clause is passed into the proc via the @SearchTerm parameter? |
#5
| |||
| |||
|
|
So basically, the user might submit one term, or multiple terms. |
#6
| |||
| |||
|
|
This can be compiled and optimized, avoids injection problems, will port easily and gives you more control over what the user is doing. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
More control over the user - don't see how |
#9
| |||
| |||
|
|
The user can be limited to how many search terms he can input at one time. If you use dynamic SQL, they can go wild and strangle the database with hundreds or thousands of requests. It is also easier to apply edits to the @search_term_# parameters, such as trimming, upper or lower casing, replacing characters, etc. |
![]() |
| Thread Tools | |
| Display Modes | |
| |