SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help Reformating SQL Syntax
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shyy
Starting Member

USA
3 Posts

Posted - 10/21/2013 :  23:33:44  Show Profile  Reply with Quote
Hi everyone,

I am having trouble reformatting this older syntax to the newer syntax.
For questions 6 and 7, how would I reformat this to match this type of format?

SELECT Employee_NameFROM EMPLOYEE_T e,
EMPLOYEE_SKILLS_T s,
SKILL_T t
WHERE e.Employee_ID = s.Employee_Id
AND s.Skill_Id = t.Skill_Id
AND t.Skill_Description = '12in Band Saw'
AND e.Employee_ID <> s.Employee_Id
AND s.Skill_Id = t.Skill_Id
AND t.Skill_Description <> '12in Band Saw'

Thank You

http://imageshack.us/photo/my-images/853/mz34.jpg/

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 10/22/2013 :  00:19:25  Show Profile  Reply with Quote
The link which you shared is not opened for me...

Any way, try this? ( rectified some of typos in the above query)

SELECT Employee_Name
FROM EMPLOYEE_T e, EMPLOYEE_SKILLS_T s, SKILL_T t
WHERE e.Employee_ID = s.Employee_Id AND s.Skill_Id = t.Skill_Id AND t.Skill_Description = '12in Band Saw'
AND e.Employee_ID <> s.Employee_Id
AND s.Skill_Id = t.Skill_Id
AND t.Skill_Description <> '12in Band Saw'


The highlighted part is fully opposite to other conditions available in the above query...

--
Chandu
Go to Top of Page

shyy
Starting Member

USA
3 Posts

Posted - 10/22/2013 :  00:53:30  Show Profile  Reply with Quote
Thanks for the reply,

The highlighted part is another condition since I need to say which Employee only has one skills where as the one you selected shows employees that have multiple skills.

Please check out this url http://imageshack.us/f/853/mz34.jpg/

This is the correct code, I just prefer this to look like the format above.

SELECT Employee_Name
FROM EMPLOYEE_T
WHERE Employee_ID IN (SELECT Employee_Id
FROM EMPLOYEE_SKILLS_T
WHERE Skill_Id IN (SELECT Skill_Id
FROM SKILL_T
WHERE Skill_Description = '12in Band Saw'))
AND
Employee_ID NOT IN (SELECT Employee_Id
FROM EMPLOYEE_SKILLS_T
WHERE Skill_Id IN (SELECT Skill_Id
FROM SKILL_T
WHERE Skill_Description <> '12in Band Saw'))




Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 10/22/2013 :  02:38:02  Show Profile  Reply with Quote
-- Alternate

SELECT Employee_Name, Employee_id
FROM EMPLOYEE_T
WHERE Employee_id IN
(SELECT est.Employee_Id
FROM EMPLOYEE_SKILLS_T est JOIN SKILL_T st ON est.Skill_Id = st.Skill_Id
GROUP BY est.Employee_Id
HAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0 )


If the above is NOT, post us back the result of the below query
SELECT est.Employee_Id
FROM EMPLOYEE_SKILLS_T est JOIN SKILL_T st ON est.Skill_Id = st.Skill_Id
GROUP BY est.Employee_Id
HAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 10/22/2013 :  08:08:20  Show Profile  Reply with Quote

SELECT e.Employee_Name, e.Employee_id
FROM EMPLOYEE_T e
INNER JOIN (SELECT est.Employee_Id
FROM EMPLOYEE_SKILLS_T est 
JOIN SKILL_T st 
ON est.Skill_Id = st.Skill_Id
GROUP BY est.Employee_Id
HAVING MIN(st.Skill_Description) = MAX(st.Skill_Description)
AND MIN(st.Skill_Description)='12in Band Saw')e1
ON e1.Employee_Id = e.Employee_Id


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

shyy
Starting Member

USA
3 Posts

Posted - 10/22/2013 :  10:09:06  Show Profile  Reply with Quote
Thank You guys both worked!

Bandi:
What does this do?
HAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0 )

visakh16:
Why did you use HAVING MIN = MAX and then use MIN and e1 at the end??

The professor gave us an SQL assignment but never showed us how to actually use it..

Thanks again for the help.

Edited by - shyy on 10/22/2013 10:19:57
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 10/22/2013 :  10:10:50  Show Profile  Reply with Quote
you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 10/22/2013 :  14:34:40  Show Profile  Reply with Quote
quote:
Originally posted by shyy

Thank You guys both worked!

Bandi:
What does this do?
HAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0 )

visakh16:
Why did you use HAVING MIN = MAX and then use MIN and e1 at the end??

The professor gave us an SQL assignment but never showed us how to actually use it..

Thanks again for the help.


MIN = MAX was to ensure you've only one unique Skill_Description available for that employee. Second condition will ensure value is '12in Band Saw' which is what you wanted
e1 is alias ie name given to derived table which contains the query ie query behaving like another table.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000