Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Syntax

Status
Not open for further replies.

Steve95

MIS
Nov 3, 2004
265
US
Hi All

Iam new to sql, Iam using sql 2000....I have a view which is returning 5 million records. I want to limit this down, I have 2 fields I want to limit this down by date and database type.

The date field is datatype: varchar
and the database type is datatype: varchar

The problem starts when I restrict the date and database type together. I only want to see certain dates and the database type within that daterange but my syntax returning all records that match the database type criteria.

select *
from vw_global
WHERE date >= '2006-09-30%' and
datebase_type like '%sale%' or datebase_type like
'%employee%'
or datebase_type like '%target%'

I hope I have made sense.

I look forward to your response.
 
Code:
select *
from vw_global
WHERE date >= '2006-09-30%' and
(datebase_type like '%sale%' or datebase_type like
'%employee%'
or datebase_type like '%target%')
and you, perhaps, should revise the date >= '2006-09-30%' expression...
 
Yes it will returns that because you didn't put any brackets around IFs"

And because I doubt you have database_type like this 'someone sale somethig' I removed ALL LIKE clauses
Code:
select *
from vw_global
WHERE date >= '2006-09-30' and
    datebase_type IN ('sale', 'employee', 'target')

but just on case I am wrong or you insist to use your first query:
Code:
select *
from vw_global
WHERE date >= '2006-09-30%' and
      (datebase_type like '%sale%'     or
       datebase_type like '%employee%' or
       datebase_type like '%target%')


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top