Wednesday, March 28, 2012
Max length for an if statement
Here is an example of what I am using.
*******************************
If (InStr({Concurrence.ConcurrenceName}, " MD", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, " COS ", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, ", M.D.", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, "M.D.", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, " M D", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, "D.O.", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, " DO", 1) > 0 _
or Instr({Concurrence.ConcurrenceName}, " DR.", 1) > 0 _
or Instr({Concurrence.ConcurrenceName}, " DR ", 1) > 0) _
or InStr({Concurrence.ConcurrenceName}, "MD", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, " DO ", 1) > 0 _
or InStr({Concurrence.ConcurrenceName}, "DR", 1) = 1) then
formula = "Physician"
ElseIf (InStr({Concurrence.ConcurrenceTitle}, "PHYSICIAN", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "ATTENDING", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "ACOS", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "COS ", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "CHIEF MEDICAL", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "CHIEF OF STAFF", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, " M.D.", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, " MD,", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "MD", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "M.D", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "D.O.", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "SURGEON", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "INTERNIST", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "DOCTOR", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, " CHIEFOFSTAFF", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "ANESTHESIOLOGIST", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "CARDIOLOGIST", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "CHIEFSOFSTAFF", 1) > 0 _
or InStr({Concurrence.ConcurrenceTitle}, "AOD", 1) > 0) then
formula = "Physician"
End If
For some reason crystal does not pull out the "PHYSICIAN" title in the second if else statement. However, if I put it in its own if statement it will evaluate properly. (I broke the if statement up for maintenance ease)
Like this:
If InStr({Concurrence.ConcurrenceTitle}, "PHYSICIAN", 1) > 0 Then
formula = "Physician"
End If
So, I am wondering if I simply have too long of an if statement and need to break this up in order to get all of the titles I am looking for.
Any suggestions on how long each if statement can be, or possibly a more efficient way to write this?
Thanks in advance.
RyanIf there are many IFs then why cant you use Case statement?sql
Saturday, February 25, 2012
Matching Strings In Different Tables Of Same Database
database and find matches for it in other tables of the same database and
have those values returned. i.e. In one table I have prospects and I want
to match their names to a table that stores the names of prospects turned
into customers. I want to write a query that looks through every entry and
returns a match for each corresponding value (from prospects to customers).
So if "Smith" is found in prospects I want SQL to return "Smith" in
customers with full contact info.
Any pointers on getting started on this is greatly appreciated. Or if you
could just point me to a reference. Obviously, I need to do some kind of
parsing. I just need to be pointed in the right direction.
Thx."Smith" <gsmith@.tbanet.org.nospam> wrote in message
news:RPWdc.410622$B81.6621293@.twister.tampabay.rr. com...
> I have a situation where I want to pull strings from one table of a SQL
2000
> database and find matches for it in other tables of the same database and
> have those values returned. i.e. In one table I have prospects and I
want
> to match their names to a table that stores the names of prospects turned
> into customers. I want to write a query that looks through every entry
and
> returns a match for each corresponding value (from prospects to
customers).
> So if "Smith" is found in prospects I want SQL to return "Smith" in
> customers with full contact info.
> Any pointers on getting started on this is greatly appreciated. Or if you
> could just point me to a reference. Obviously, I need to do some kind of
> parsing. I just need to be pointed in the right direction.
> Thx.
If you are matching name columns, then this may be in the right direction:
select
c.CustomerID,
c.LastName,
c.CompanyName,
c.ContactPhone,
...
from
dbo.Customers c
join dbo.Prospects p
on c.LastName = p.LastName
where
p.LastName = 'Smith'
If this isn't what you're looking for, it would be helpful if you could post
CREATE TABLE statements for the tables, pluse INSERT statements for some
sample data, and the results you expect.
Simon|||"Smith" <gsmith@.tbanet.org.nospam> wrote in message
news:RPWdc.410622$B81.6621293@.twister.tampabay.rr. com...
> I have a situation where I want to pull strings from one table of a SQL
2000
> database and find matches for it in other tables of the same database and
> have those values returned. i.e. In one table I have prospects and I
want
> to match their names to a table that stores the names of prospects turned
> into customers. I want to write a query that looks through every entry
and
> returns a match for each corresponding value (from prospects to
customers).
> So if "Smith" is found in prospects I want SQL to return "Smith" in
> customers with full contact info.
> Any pointers on getting started on this is greatly appreciated. Or if you
> could just point me to a reference. Obviously, I need to do some kind of
> parsing. I just need to be pointed in the right direction.
> Thx.
If you are matching name columns, then this may be in the right direction:
select
c.CustomerID,
c.LastName,
c.CompanyName,
c.ContactPhone,
...
from
dbo.Customers c
join dbo.Prospects p
on c.LastName = p.LastName
where
p.LastName = 'Smith'
If this isn't what you're looking for, it would be helpful if you could post
CREATE TABLE statements for the tables, pluse INSERT statements for some
sample data, and the results you expect.
Simon