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 |
abhishekmadas
Starting Member
19 Posts |
Posted - 2005-04-27 : 12:38:44
|
I am facing a problem writing a query.The problem is I have a column with different formulas of chemical molecules. for eg CH3Cl CbF-(Cb2) CBF-(Ca)Now I wrote this query SELECT *from tbl where MolFormula LIKE 'Cb%'This returns me row 2 and row 3 whereas I just need row 2 to be returned. I am using MS Access. Thanks for looking into it. |
|
Kristen
Test
22859 Posts |
Posted - 2005-04-27 : 13:45:49
|
SELECT * from tbl where MolFormula COLLATE Latin1_General_BIN LIKE 'Cb%'Kristen |
 |
|
Kristen
Test
22859 Posts |
Posted - 2005-04-27 : 13:46:35
|
Aggghhhh - is this Access? If so don't know, sorry.Kristen |
 |
|
mfemenel
Professor Frink
1421 Posts |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-04-27 : 15:28:15
|
You can also use the INSTR() function, if you want to similate a LIKE a little better. The 4th argument, usually ommited, can be set to 0 which indicates to use a binary compare, just as in strcomp().WHERE INSTR(1,MolFormula,"CB",0) <> 0that should be the "case sensitive" equivalent to WHERE MolFormula LIKE "*CB*".- Jeff |
 |
|
abhishekmadas
Starting Member
19 Posts |
Posted - 2005-04-27 : 16:03:08
|
Thanks. You have probably gotten the answer for me. Am really close.SELECT MolFormualaFROM Group_Tablewhere INSTR(1,MolFormula,'Cbf',0)<>0This query returns all molecules containing 'Cbf' but making a case sensitive search. This is what the result set isMolFormulaCbf-(Cb,2Cbf)Cbf-(3Cbf)Cbf-(2Cb,Cbf) Cbf-(Cbf,2Nb)Cb-(C,Cbf,Cb)CbBr-(Cbf,Cb)CbCl-(Cbf,Cb)CbH-(Cbf,Cb)pretty good. But now I want only those that start with Cbf i.e. the first 4 rows.I tried to further filter :SELECT MolFormula FROM(SELECT MolFormula FROM Group_Tablewhere INSTR(1,MolFormula,'Cbf',0)<>0)WHERE MolFormula LIKE '%Cbf%'but I don't get any results. Where am I going wrong? |
 |
|
abhishekmadas
Starting Member
19 Posts |
Posted - 2005-04-27 : 16:05:16
|
sorry printing error:WHERE MolFormula LIKE 'Cbf%'No result set. |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-04-27 : 16:51:46
|
what does INSTR return? Look up the function in Access VBA help. Can you figure out what you should change? I'll give you a clue -- you only want rows in which the INSTR() returns a value that tells you that the string begins with the characters you are looking for....- Jeff |
 |
|
|
|
|
|
|