AUTHOR

i need SQL help

here's my query:
select fname, lname, state, zip, company, contact_phone
from insurance, patient, insure
where state = 'OH' or 'KY'
and company = insurance$company
and id = patient$id
order by lname

here's my error:
Msg 4145, Level 15, State 1, Line 4
An expression of non-boolean type specified in a context where a condition is expected, near 'and'.

the fuck.

-This message has been edited by shr00mie on 7/31/2011 5:16:31 AM

WHERE state IN ('OH','KY')
you're awesome.
FriendZone quote:
WHERE state IN ('OH','KY')
Alternately, WHERE state = 'OH' OR state = 'KY'
You could also do

WHERE (state = 'OH' OR state = 'KY')


I think.
fuck. i was trying to combine them improperly.

although trying to do this homework at 1:20am was probably not the best idea.

thanks guys.
I've only done C++
Nobody should have to do SQL at 1:20 AM. At least not without a Big Pile O' Cash.

Good luck.
shr00mie quote:
fuck. i was trying to combine them improperly.

although trying to do this homework at 1:20am was probably not the best idea.

thanks guys.
Seriously, you'll end up missing easy stuff after staring at it for too long.
in () looks way cleaner. and seems to be more useful when searching for multiple values from a particular column. saves typing a bunch of or statements.
apparition32 quote:
Nobody should have to do SQL at 1:20 AM. At least not without a Big Pile O' Cash.

Good luck.
meh. gotta learn this stuff somehow. and it's not going to happen anytime during the 45hr work week. i have no life till next june. and sql is surprisingly interesting as i'm learning more about it.

the queries themselves are not all that difficult to grasp. the art in it seems to really come from building ridiculously complex queries for databases that have hundreds of tables and presenting the information in a way that yields something useable.

word on the street is sql people get paid the big bucks.

-This message has been edited by shr00mie on 7/31/2011 5:28:06 AM

FriendZone quote:
Seriously, you'll end up missing easy stuff after staring at it for too long.
there's also the part where this is my first week writing sql queries, so i'm rather noobish ATM.
You can use IN for sub selects too, returning multiple values for a single variable linking tables.
here's another question as far as best practice goes.

you've got two tables. they both have a phone column. is it best practice to give them unique names such as patient.phone and doctor.phone as to avoid ambiguity?
are there certain naming conventions that are standard for columns like that? would you go with PatientPhone, patient_phone, or patient.phone
shr00mie quote:
there's also the part where this is my first week writing sql queries, so i'm rather noobish ATM.
Nice.

I used PLSQL developer at work all day every day. Welcome to the *.club
shr00mie quote:
meh. gotta learn this stuff somehow. and it's not going to happen anytime during the 45hr work week. i have no life till next june. and sql is surprisingly interesting as i'm learning more about it.

the queries themselves are not all that difficult to grasp. the art in it seems to really come from building ridiculously complex queries for databases that have hundreds of tables and presenting the information in a way that yields something useable.

word on the street is sql people get paid the big bucks.

-This message has been edited by shr00mie on 7/31/2011 5:28:06 AM


They tend to do well. Learn stored procedures, database design principles, and some front-end skills like C#/.Net, and you'll do well. One of very few fields that still has growing demand right now, in this economy.
apparition32 quote:
They tend to do well. Learn stored procedures, database design principles, and some front-end skills like C#/.Net, and you'll do well. One of very few fields that still has growing demand right now, in this economy.
i don't know if i'll end up on the DB side of things. getting another degree in network system admin and this database development is one of my core classes, not necessarily my focus.

at work i'm mainly IT coordinator for the LA office. the head IT guy at the NY HQ wants to train me to be his west coast counterpart for this new thinclient architecture they're rolling out for our company internationally...

BUT. all said. it's good to have a general understanding of DBs. Smiley
Id recommend always being descriptive and short with column names.

dr_phone and pat_phone

That way if you ever select all patients of doctor x, you can distinguish data easily
shr00mie quote:
are there certain naming conventions that are standard for columns like that? would you go with PatientPhone, patient_phone, or patient.phone
Do the first or second, a period is a reserved delimiter, which in your example, would mean patient table, field "phone".

Other than that, although people toss around standards, one really hasn't emerged as a naming convention. The one that's getting traction, though, is table names in the singular (e.g. "Customer" over "Customers''), for clarity when working with Object Relational Mapping tools. Table names singular, objects instantiated from the tables plural.

-This message has been edited by apparition32 on 7/31/2011 5:37:49 AM

Quick reply

Sign in to post a message.
Smileys

Times shown in Eastern Time (ET).