| Author |
Topic |
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-07-24 : 05:40:32
|
| Hi,I need to check a string in procedure if that is alphanumeric or notmeans:123aaa : Acceptedaaaaaa : not accepted123123 : not acceptedhow to fulfill this condition?No special character allowed also.Please help!Pushkar |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-24 : 05:43:32
|
try this?BEGIN TRANDECLARE @sample TABLE ( [value] VARCHAR(MAX) )INSERT @sample ([value])VALUES ('123aaa') , ('aaaaaa') , ('123123')SELECT * FROM @sampleWHERE [value] LIKE '%[a-Z]%' AND [value] LIKE '%[0-9]%' ROLLBACKTransact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-07-24 : 05:44:30
|
col like '%[0-9]%' AND col like '%[^0-9]%' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-07-24 : 06:05:28
|
quote: Originally posted by webfred col like '%[0-9]%' AND col like '%[^0-9]%' No, you're never too old to Yak'n'Roll if you're too young to die.
May not be accurate for data like 123#$7MadhivananFailing to plan is Planning to fail |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-07-24 : 06:27:42
|
| I just added NOT LIKE '%[!@#$%^&*()_+=-.":;><,/?\|]%'So the statement is as belowIF(@string LIKE '%[^a-z]%' AND @string LIKE '%[^0-9]%' AND @string NOT LIKE '%[!@#$%^&*()_+=-.":;><,/?\|]%')thanks for the quick responce guys, made my days |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-07-24 : 06:43:33
|
| Have you tried TC's method that would be simpleMadhivananFailing to plan is Planning to fail |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-07-24 : 06:47:11
|
quote: Originally posted by madhivanan
quote: Originally posted by webfred col like '%[0-9]%' AND col like '%[^0-9]%' No, you're never too old to Yak'n'Roll if you're too young to die.
May not be accurate for data like 123#$7MadhivananFailing to plan is Planning to fail
I thought EXACTLY this is accurate  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-24 : 07:00:23
|
I think OP edited post to include a requirement not to include special characters.This then is probably the nicest way of doing itDECLARE @sample TABLE ( [value] VARCHAR(MAX) )INSERT @sample ([value])VALUES ('123aaa') , ('aaaaaa') , ('123123') , ('asdsad"£"!3sad') , ('a+3')SELECT * FROM @sampleWHERE [value] LIKE '%[a-Z]%' AND [value] LIKE '%[0-9]%' AND [value] NOT LIKE '%[^0-Z]%'Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-07-24 : 07:39:18
|
you were actually perfect TC thanks for the logic....quote: Originally posted by Transact Charlie I think OP edited post to include a requirement not to include special characters.This then is probably the nicest way of doing itDECLARE @sample TABLE ( [value] VARCHAR(MAX) )INSERT @sample ([value])VALUES ('123aaa') , ('aaaaaa') , ('123123') , ('asdsad"£"!3sad') , ('a+3')SELECT * FROM @sampleWHERE [value] LIKE '%[a-Z]%' AND [value] LIKE '%[0-9]%' AND [value] NOT LIKE '%[^0-Z]%'Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/
|
 |
|
|
|