Solved

Multiple Like Statements -- more effiicient?

Posted on 2007-11-16
3
478 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 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: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
 

Author Comment

by:Travidia
ID: 20301684
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
monitoring configuration for SQL server DB 32 50
Table where row act as column 11 71
Need to replicate a Log table 4 13
Need SQL Update 2 10
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

730 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