home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,741 of 19,505   
   Erland Sommarskog to steve   
   Re: How to query when a text field is to   
   26 Jan 10 22:49:47   
   
   2d83b2ce   
   From: esquel@sommarskog.se   
      
   steve (tinker123@gmail.com) writes:   
   > I'm trying to find the number of records in a table where field_1 is   
   > not a substring in field_2.   
   >   
   > My problem with the query below is that field_2 is a text field and is   
   > too fat to convert in order to use the LIKE operator  ( I get "field   
   > would be truncated" messages )   
   >   
   > select count(*) as COUNT_Bad_Records from MyTable   
   > where   
   > field_1 not like CAST(field_2 as varchar(max)) +'%'   
   >   
   > Any suggestions for how else I might get to the same result?   
      
   I suspect that there is something you are not telling us. I tried   
   this on SQL 2005:   
      
      CREATE TABLE sometable (field_1 text NULL, field_2 text NULL)   
      
      select count(*) as COUNT_Bad_Records from sometable   
      where   
      field_1 not like CAST(field_2 as varchar(max)) +'%'   
      go   
      drop table sometable   
      
   and it complete without error.   
      
   Could you post the actual code and the actual error message?   
      
      
   --   
   Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se   
      
   Links for SQL Server Books Online:   
   SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx   
   SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx   
   SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca