| Author |
Topic |
|
wizbay
Starting Member
3 Posts |
Posted - 2010-11-27 : 05:56:25
|
| Hi. I am trying create a stored procedure to check if a passed string parameter contains a bad word from badword table. For example, I'd excute "sp_isthisbad @word='shityou'" and sp_isthisbad checks if the passed word is in the badword table. badword table consit of wordId int and word varchar(50). Since this table contains a row 5, "shit", it shoule be filtering the word "shityou"Please anyone helps me with this issue. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-27 : 06:47:21
|
| you can use PATINDEX or LIKE for achieving this------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
MohanKandasamy
Starting Member
9 Posts |
Posted - 2010-11-27 : 07:37:03
|
| Hi,Please use the below stored procedure as per your requestALTER PROC SP_ISTHISBAD (@word as varchar(40))AS SELECT * FROM BADWORD WHERE PATINDEX('%[ -Z]%',@word) > 0in case if you want to pass any character, please check regular expression of Patindex.Note : Please check fulltext search topic also your Knowledge.RegardsMohan KandasamyMohan Kandasamy |
 |
|
|
wizbay
Starting Member
3 Posts |
Posted - 2010-11-27 : 07:47:10
|
quote: Originally posted by MohanKandasamy Hi,Thanks I'll try this. Please use the below stored procedure as per your requestALTER PROC SP_ISTHISBAD (@word as varchar(40))AS SELECT * FROM BADWORD WHERE PATINDEX('%[ -Z]%',@word) > 0in case if you want to pass any character, please check regular expression of Patindex.Note : Please check fulltext search topic also your Knowledge.RegardsMohan KandasamyMohan Kandasamy
|
 |
|
|
wizbay
Starting Member
3 Posts |
Posted - 2010-11-27 : 18:22:49
|
Hm..for some reason, this stored procedure doesn't work even if I pass an exact word.quote: Originally posted by MohanKandasamy Hi,Please use the below stored procedure as per your requestALTER PROC SP_ISTHISBAD (@word as varchar(40))AS SELECT * FROM BADWORD WHERE PATINDEX('%[ -Z]%',@word) > 0in case if you want to pass any character, please check regular expression of Patindex.Note : Please check fulltext search topic also your Knowledge.RegardsMohan KandasamyMohan Kandasamy
|
 |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2010-11-27 : 18:52:08
|
I think the patindex should be using the variable passed as the condition, and the column from the badword table as the match...but this works. I apply UPPER to remove any option of case sensitivity issues..Create table BADWORD ( wordlist char(40) not null)GoInsert into BADWORD Select 'Cacayou' UNIONSelect 'youCaca' GOCreate PROC SP_ISTHISBAD (@word as varchar(40))ASSELECT UPPER(wordlist) FROM BADWORD WHERE Patindex('%'+@word+'%',wordlist)>0GOGOExec SP_ISTHISBAD 'Cacayou' --returns 1 recordExec SP_ISTHISBAD 'Caca' --returns both records Poor planning on your part does not constitute an emergency on my part. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-28 : 02:42:18
|
it should be oppositemake this sp as belowCreate PROC SP_ISTHISBAD (@word as varchar(40))ASDECLARE @ReplacedWord varchar(max)SELECT @ReplacedWord = CASE WHEN @ReplacedWord IS NULL THEN REPLACE(@word,wordlist,'') ELSE REPLACE(@ReplacedWord,wordlist,'') ENDFROM BADWORDSELECT @ReplacedWordGOand call it likeDECLARE @word varchar(max)SELECT @word = 'you''re absolute Cacayou and a youCaca'EXEC SP_ISTHISBAD @word ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-28 : 02:45:05
|
| also just noticed you're using sp_ as name from procedure. Please dont name user stored procedures like this. Reason is belowseehttp://sqlserverpedia.com/blog/sql-server-bloggers/stored-procedure-performance-using-%E2%80%9Csp_%E2%80%9D-prefix-%E2%80%93-myth-or-fact/------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|