On Jan 12, 5:51 pm, Jeremy Evans <[email protected]> wrote:
> On Jan 12, 2:18 pm, Hillary <[email protected]> wrote:
>
> > I want to use a charindex in one of my queries. How would that work with
> > sequel.
>
> > Example query is below
>
> > SELECT   distinct Name
> > FROM     SomeTable
> > WHERE    Catalog_ID  = 'catalog'
> > AND             Function_Name = 'Artist'
> > AND             CHARINDEX(',', Name) = 0
>
> This uses the virtual row syntax for SQL functions:
>
>   DB[:SomeTable].
>     distinct.
>     select(:Name).
>     where(:Catalog_ID=>'catalog', :Function_Name=>'Artist')
> {{charindex(',', :Name)=>0}}
>
> You could also just use Symbol#sql_function:
>
>   DB[:SomeTable].
>     distinct.
>     select(:Name).
>
> where(:Catalog_ID=>'catalog', :Function_Name=>'Artist', 
> :CHARINDEX.sql_function(',', :Name)=>0)
>
> Jeremy

Or

DB[:SomeTable].
  distinct.
  select(:Name).
  filter{[:Catalog_ID => 'catalog',
          :Function_name => 'Artist',
          charindex(',', :Name) => 0]}

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to