String within sql statement

hi, nice easy one for first thing mornday morning :)  

I need to add "JDC" as an exception in my Where section, what am I doing wrong?

cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "SELECT Surname, FirstName, EmployeeSkills.EmployeeId, SkillsName, SkillLevel, " & _
        "Convert(varchar(10), ExpiryDate, 103) as ExpiryDateOnly, CardColour, AccDescription FROM EmployeeSkills " & _
        "LEFT JOIN SkillLevel ON (SkillLevel.SkillLevelId = EmployeeSkills.SkillLevelId) " & _
        "LEFT JOIN SkillsType ON (SkillsType.SkillId = EmployeeSkills.SkillId) " & _
        "LEFT JOIN Employees ON (Employees.Employeeid = EmployeeSkills.EmployeeId) " & _
        "LEFT JOIN AccRoute ON (AccRoute.AccRouteId = EmployeeSkills.AccRouteId) " & _
        "Where EmployeeSkills.EmployeeId = EmployeeSkills.EmployeeId and EmployeeSkills.SkillId = EmployeeSkills.SkillId and trainingtypeName <>  " JDC " 
Andrew ParkerIT Field Systems Delivery OfficerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cubixSoftwareCommented:
Try single quotes

       "Where EmployeeSkills.EmployeeId = EmployeeSkills.EmployeeId and EmployeeSkills.SkillId = EmployeeSkills.SkillId and trainingtypeName <>  ' JDC '"

0
cubixSoftwareCommented:
or

"Where EmployeeSkills.EmployeeId = EmployeeSkills.EmployeeId and EmployeeSkills.SkillId = EmployeeSkills.SkillId and trainingtypeName <>  'JDC'"

depending if you want to check for embedded spaces as well
0
Andrew ParkerIT Field Systems Delivery OfficerAuthor Commented:
ok that works, but gives me too many rows,

Tables are

EmployeeSkills = employeeid, SkillId
SkillsType = SkillId, SkillsName, TrainingTypeId
TrainingType = TrainingTypeId, TrainingTypeName

What I need is a listview of everyone without TrainingType in JDC

Code so far

"SELECT Surname, FirstName, EmployeeSkills.EmployeeId, SkillsName, SkillLevel, " & _
        "Convert(varchar(10), ExpiryDate, 103) as ExpiryDateOnly, CardColour, AccDescription, Trainingtypename FROM EmployeeSkills " & _
        "LEFT JOIN SkillLevel ON (SkillLevel.SkillLevelId = EmployeeSkills.SkillLevelId) " & _
        "LEFT JOIN SkillsType ON (SkillsType.SkillId = EmployeeSkills.SkillId) " & _
        "LEFT JOIN Employees ON (Employees.Employeeid = EmployeeSkills.EmployeeId) " & _
        "LEFT JOIN TrainingType ON (SkillsType.SkillId = EmployeeSkills.SkillId) " & _
        "LEFT JOIN AccRoute ON (AccRoute.AccRouteId = EmployeeSkills.AccRouteId) " & _
       "Where EmployeeSkills.EmployeeId = EmployeeSkills.EmployeeId and EmployeeSkills.SkillId = EmployeeSkills.SkillId and trainingtypeName <> 'JDC' Order by Surname"

There should only be one trainingType to a skill, but this seems to give me multiple entries?

Hopefully you can help, but it does help understand the problem from my end explaining to others, all help is gratefully received :)
0
cubixSoftwareCommented:
TRY

"LEFT JOIN TrainingType ON (TrainingType.TrainingTypeId = SkillsType.TrainingTypeId) " & _


you hadn't joined the training type table to anything so therefore you will get all records where description <> 'JDC' and not jus those linked to the skill type you have selected


HTH :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andrew ParkerIT Field Systems Delivery OfficerAuthor Commented:
thanks, i noticed that after I asked, it really does help your thinking when you type it out trying to explain in english what you need help with :)

Lots of points for you today cubix, cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.