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 |
|
kushalagarwal
Starting Member
1 Post |
Posted - 2010-07-30 : 06:54:44
|
| Hello, Could anyone please tell me if there is a way to write Regular Expressions and Between in the same query?I have a table with a column orderNumber. The orderNumber has preceeding 0's and .'s something like "00000034500.1.2.1.1".There are two input textboxes according to whose values search queries should be fired. What I would like to do is:Lets say there are 3 orders with orderNumber "00000034500" ,"00000034600" and "00000034700".1) If 1 textbox is entered with value "345" and the other is blank I would like to search for the order "00000034500.1.2.1.1"I am pretty new to DB's, but I suppose I can use a regular expression (REGEX_LIKE) to search this order number(Please correct me if I am wrong). 2) If both textboxes are entered with values "345" and "347"I would like it to search for all 3 orders. Also, the length of the orderNumbers is not fixed Is it possible to do this? Thanks in advance,Cheers,Kushal |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2010-08-17 : 09:06:43
|
| your sample data is vague...but here is something that you can play around with...create table table1(col1 varchar(100))insert into table1select '00000034500.1.2.1.1'unionselect '00000034600.1.2.1.1'unionselect '00000034700.1.2.1.1'declare @text1 intdeclare @text2 intset @text1=345set @text2=346select *from table1where left(replace(col1,'0',''),patindex('%.%',replace(col1,'0',''))-1) between @text1 and coalesce(@text2,@text1)drop table table1--------------------keeping it simple... |
 |
|
|
|
|
|
|
|