Solved

Multiple Like Statements -- more effiicient?

Posted on 2007-11-16
3
443 Views
Last Modified: 2010-08-05
I have this query with the conditions of username like %.  I wondered if there is an easier way to do this without having to break into two separate blocks.
Also, is there a more efficient way to get the Dates that I'm using?  

where username like 'gp0%'  
and r.key3 <>0
--and detail = 'INVOCATION_BEGIN'
and type in ('FD_Command','FD_SAVE','FD_SKIP')
and (ra.action_time between (CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime)-1)
and (CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime)-0))

or username like 'ybrant0%'  
and r.key3 <>0
--and detail = 'INVOCATION_BEGIN'
and type in ('FD_Command','FD_SAVE','FD_SKIP')
and (ra.action_time between (CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime)-1)
and (CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime)-0))
0
Comment
Question by:Travidia
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 20300516
where (username like 'gp0%'  or username like 'ybrant0%' )
and r.key3 <>0
--and detail = 'INVOCATION_BEGIN'
and type in ('FD_Command','FD_SAVE','FD_SKIP')
and (ra.action_time between (CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime)-1)
and (CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime)-0))
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 20300531
>> Also, is there a more efficient way to get the Dates that I'm using? <<

Nah, the date handling is fine.  Manipulation on GETDATE() is much preferred; after all, for a SELECT it will only have to be done once anyway.

What you want to avoid is performing any function on the table column, in this case
ra.action_time
and you did avoid that: you performed no function against that column.

So the date part is fine.
0
 

Author Comment

by:Travidia
ID: 20301684
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now