Click here to Skip to main content
15,889,034 members
Home / Discussions / Database
   

Database

 
GeneralRe: whats the proper defination of view Pin
Colin Angus Mackay9-Mar-05 14:53
Colin Angus Mackay9-Mar-05 14:53 
Generalit is givi ng me syntax error Pin
feeha9-Mar-05 7:37
feeha9-Mar-05 7:37 
GeneralRe: it is givi ng me syntax error Pin
ToddHileHoffer9-Mar-05 8:32
ToddHileHoffer9-Mar-05 8:32 
GeneralRe: it is givi ng me syntax error Pin
feeha9-Mar-05 9:26
feeha9-Mar-05 9:26 
GeneralQuestion on UNION syntax Pin
KreativeKai9-Mar-05 6:06
professionalKreativeKai9-Mar-05 6:06 
GeneralRe: Question on UNION syntax Pin
ToddHileHoffer9-Mar-05 8:35
ToddHileHoffer9-Mar-05 8:35 
GeneralRe: Question on UNION syntax Pin
Edbert P9-Mar-05 13:11
Edbert P9-Mar-05 13:11 
GeneralRe: Question on UNION syntax Pin
KreativeKai10-Mar-05 4:25
professionalKreativeKai10-Mar-05 4:25 
Well, I’ve posted my question on two message boards and received several suggestions. First of all Thanks for all your feedback and help!!

Below are the two approaches that I’ve received and I’ve tweaked them to get the result set I was looking for. Table one includes everyone on our payroll including terminated employees. Table two is our health insurance table which includes retirees. The emp number will match especially with the retirees. The problem also comes into play when you have retirees come back to work on a contractual basis. Somedays I wish they would just go golfing. Roll eyes | :rolleyes:

Hopefully my explanation above helps in understanding the data I’m trying to select. Both of the selects below work where we include all the active folks on our payroll (table1), plus all the active health insurance participants (table2). Both code snipplets also weed out the duplicate Retirees and only list them once.

I now have the question; Is one section of code using a stored procedure is more efficient than the other? I’ve tested both selects in my VB.NET project and the second code snipplet is about 50 milliseconds faster. My record count is 1578. Even if the second code snipplet is faster, is it more efficient to use the join? Nobody will really notice 50 milliseconds, so I want to go with the code that will take the least amount of resources from SQL. I used Query analyzer to perform an Estimated Execution Plan and didn’t notice any real differences. Of course I’m new to this, and not sure what I’m looking at.

Any suggestions or feedback is appreciated!! Again, thanks for the great feedback you’ve already given!! Smile | :)

SELECT [table1].LastName, [table1].FirstName, [table1].EmpNo AS EmpID
	FROM table1
	WHERE EmpTermDate IS NULL 
UNION
SELECT [table2].LastName, [table2].FirstName, [table2].SocSecNo AS EmpID
	FROM table2
		LEFT JOIN [table1] ON [table2].SocSecNo = [table1].EmpNo
	WHERE [table1].EmpNo IS NULL
		OR 
			([table1].EmpNo IS NOT NULL
				 AND 
			[table1].EmpTermDate IS NOT NULL)
	ORDER BY LastName ASC, FirstName ASC, EmpID ASC

SELECT LastName,FirstName,EmpNo AS EmpID
FROM table1
WHERE EmpTermDate IS NULL 
UNION
SELECT LastName, FirstName, SocSecNo AS EmpID
FROM table2 
WHERE SocSecNo NOT IN (SELECT EmpNo FROM table1 WHERE EmpTermDate IS NULL)
ORDER BY LastName ASC,FirstName ASC, EmpID ASC

Lost in the vast sea of .NETNET
GeneralRe: Question on UNION syntax Pin
Edbert P10-Mar-05 15:36
Edbert P10-Mar-05 15:36 
GeneralRe: Question on UNION syntax Pin
KreativeKai11-Mar-05 3:15
professionalKreativeKai11-Mar-05 3:15 
GeneralTrancation Replication Problems Pin
tyaramis9-Mar-05 0:19
tyaramis9-Mar-05 0:19 
GeneralDBF Export from SQL server Pin
davethiss9-Mar-05 0:06
davethiss9-Mar-05 0:06 
GeneralHow Pin
Yulianto.8-Mar-05 17:46
Yulianto.8-Mar-05 17:46 
GeneralRe: How Pin
Yulianto.8-Mar-05 18:07
Yulianto.8-Mar-05 18:07 
GeneralRe: How Pin
ToddHileHoffer9-Mar-05 8:38
ToddHileHoffer9-Mar-05 8:38 
Questionhow to create a view in sql Pin
feeha8-Mar-05 9:10
feeha8-Mar-05 9:10 
AnswerRe: how to create a view in sql Pin
Chris Meech8-Mar-05 9:34
Chris Meech8-Mar-05 9:34 
AnswerRe: how to create a view in sql Pin
Anonymous10-Mar-05 0:26
Anonymous10-Mar-05 0:26 
Questionhow to save pic Pin
javad_20058-Mar-05 7:05
javad_20058-Mar-05 7:05 
AnswerRe: how to save pic Pin
ToddHileHoffer8-Mar-05 7:28
ToddHileHoffer8-Mar-05 7:28 
GeneralNeed a Help Pin
Anonymous8-Mar-05 5:42
Anonymous8-Mar-05 5:42 
GeneralRe: Need a Help Pin
Chris Meech8-Mar-05 5:51
Chris Meech8-Mar-05 5:51 
GeneralRe: Need a Help Pin
Anonymous8-Mar-05 11:57
Anonymous8-Mar-05 11:57 
GeneralRe: Need a Help Pin
Shawn200014-Mar-05 4:45
Shawn200014-Mar-05 4:45 
GeneralCopy recordsets Pin
Seraphin7-Mar-05 23:24
Seraphin7-Mar-05 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.