| Author |
Topic |
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2009-12-04 : 15:18:38
|
| In a perfect world I would write code like this.SELECTp.ProductCode AS "productcode", pe.UPC_code AS UPCFROM Products pINNER JOIN Products_Descriptions pd ON p.ProductID = pd.ProductIDINNER JOIN Products_Extended pe ON pd.ProductID = pe.ProductIDWHERE (p.HideProduct is NULL OR p.HideProduct <> 'Y')AND (pe.metatag_description IS $%~!!!In ALL CAPS!!!~%$)ORDER BY p.ProductCodebut we are not in a perfect world.How can I get it to give me a list wherein all the data in a certain column is in ALL CAPS?To be clear, some of the data is already in ALL CAPS, other is not. I want to be able to look only at the data in ALL CAPS. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2009-12-04 : 15:58:11
|
| Wont that MAKE them uppercase, instead of finding the ones that are uppercase? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-12-04 : 16:15:11
|
Not going to be terribly efficient if there are a lot of records but this will do itcreate table #t (a varchar(10))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');SELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a)) |
 |
|
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2009-12-04 : 16:25:28
|
| there are three thousand recordssome are likeAjkjdkjAjkdjkdfDjdklajkldjdothers likedjkfajdflkajand more likeAJAKLJDFKLJADKLFJALDJFLAAKLDJFI need to find the ones that are like AJAKLJDFKLJADKLFJALDJFLAAKLDJF and have it spit out only those |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-04 : 16:49:18
|
| Russell's solution should work for you...no? |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-12-07 : 01:34:14
|
| Hi u can also try thiscreate table #t (a varchar(10))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');select * from #t where a = UPPER(a) collate latin1_general_cs_as |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-12-07 : 04:53:47
|
quote: Originally posted by russell Not going to be terribly efficient if there are a lot of records but this will do itcreate table #t (a varchar(10))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');SELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a))
Your solution doesn't work in all conditions. See below example..create table #t (a varchar(100))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');insert #t values ('HOLLYWOOD BACKSTORIES: DR. DOLITTLE goes behind the scenes of the hit comedy starring Eddie Murphy.')Your Solution: SELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a))My Solution : select * from #t where a = UPPER(a) collate latin1_general_cs_asdrop table #t |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-07 : 04:59:53
|
quote: Originally posted by raky
quote: Originally posted by russell Not going to be terribly efficient if there are a lot of records but this will do itcreate table #t (a varchar(10))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');SELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a))
Your solution doesn't work in all conditions. See below example..create table #t (a varchar(100))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');insert #t values ('HOLLYWOOD BACKSTORIES: DR. DOLITTLE goes behind the scenes of the hit comedy starring Eddie Murphy.')Your Solution: SELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a))My Solution : select * from #t where a = UPPER(a) collate latin1_general_cs_asdrop table #t
It is becuase no size is given for varbinaryTry withSELECT * FROM #t WHERE Convert(varbinary(1000), a) = Convert(varbinary(1000), UPPER(a))This is the reason we should provide the size during the datatype convertion. See thishttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-12-07 : 05:07:22
|
quote: Originally posted by madhivanan
quote: Originally posted by raky
quote: Originally posted by russell Not going to be terribly efficient if there are a lot of records but this will do itcreate table #t (a varchar(10))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');SELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a))
Your solution doesn't work in all conditions. See below example..create table #t (a varchar(100))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');insert #t values ('HOLLYWOOD BACKSTORIES: DR. DOLITTLE goes behind the scenes of the hit comedy starring Eddie Murphy.')Your Solution: SELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a))My Solution : select * from #t where a = UPPER(a) collate latin1_general_cs_asdrop table #t
It is becuase no size is given for varbinaryTry withSELECT * FROM #t WHERE Convert(varbinary(1000), a) = Convert(varbinary(1000), UPPER(a))This is the reason we should provide the size during the datatype convertion. See thishttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspxMadhivananFailing to plan is Planning to fail
yes you are right madhivanan just now iam about to say that word by the time you posted about that..better to use varbinary(max) |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-12-07 : 05:57:08
|
Why all the converts?What's wrong with this?create table #t (a varchar(10))insert #t values ('Russell');insert #t values ('russell');insert #t values ('RUSSELL');-- RusselSELECT * FROM #t WHERE Convert(varbinary, a) = Convert(varbinary, UPPER(a))-- CharlieSELECT * FROM #t WHERE [a] NOT LIKE '%[abcdefghijklmnopqrstuvwxyz]%' COLLATE SQL_Latin1_General_Cp1_CS_ASDROP TABLE #tis the LIKE going to be any slower?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|