Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
moramoga
Starting Member
34 Posts |
Posted - 2008-01-23 : 15:39:39
|
Hi guys, This is kind of a noob questions, but here it goees. I have this store procedureALTER PROCEDURE [dbo].[search1] @customer Varchar(5000), @subject varchar(5000) AS BEGIN TRAN SELECT * FROM FormWHERE (subject LIKE %@subject%) AND (customer = @customer) BEGIN COMMIT TRAN; RETURN 0 END BEGIN ROLLBACK TRAN; RETURN 1; END I know there is an error on %@subject%, can someone tell me the right way to do this? |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2008-01-23 : 16:25:41
|
You need quotes...quote: Originally posted by moramoga Hi guys, This is kind of a noob questions, but here it goees. I have this store procedureALTER PROCEDURE [dbo].[search1] @customer Varchar(5000), @subject varchar(5000) AS BEGIN TRAN SELECT * FROM FormWHERE (subject LIKE '%' + @subject + '%') AND (customer = @customer) BEGIN COMMIT TRAN; RETURN 0 END BEGIN ROLLBACK TRAN; RETURN 1; END I know there is an error on %@subject%, can someone tell me the right way to do this?
Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
moramoga
Starting Member
34 Posts |
Posted - 2008-01-23 : 16:46:51
|
| Thank you very much :) |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2008-01-23 : 18:32:41
|
| Just FYI that the search might not be efficient. Your use of wild cards before will prevent any indexes to be used..Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-01-23 : 18:48:35
|
quote: Originally posted by dinakar Just FYI that the search might not be efficient. Your use of wild cards before will prevent any indexes to be used..
Only on the subject. The customer stuff will use an index, which is likely to be a good choice anyway. |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2008-01-23 : 19:32:44
|
quote: Originally posted by LoztInSpace
quote: Originally posted by dinakar Just FYI that the search might not be efficient. Your use of wild cards before will prevent any indexes to be used..
Only on the subject. The customer stuff will use an index, which is likely to be a good choice anyway.
Yes ofcourse.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
|
|
|