Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple Like Statements -- more effiicient?

Posted on 2007-11-16
3
Medium Priority
?
497 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 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 70

Expert Comment

by:Scott Pletcher
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

597 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