Solved

Multiple Like Statements -- more effiicient?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net and sql server 4 37
Sql Query 6 68
horizontal scale out 29 18
SQL Server syntax 4 25
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

825 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