?
Solved

Multiple Like Statements -- more effiicient?

Posted on 2007-11-16
3
Medium Priority
?
488 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 69

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 69

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

770 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