Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
erickcm18
Starting Member
2 Posts |
Posted - 2011-02-04 : 12:04:33
|
| Hi,I have a payroll database. In the profile some employees have the title "Agent" and other employees have "Manager". I have 2 views(1 for Agent and another for manager) Views: 1- dbo.attendance2- dbo.attendance_nonBasically my question is what SQL script can I use to indicate:Select *From dbo.attendancewhere title = 'agent'IF NOT Select the other View (dbo.attendance_non)this last line is my problem.Thank you |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2011-02-04 : 12:07:34
|
Use not exists perhaps...Select *From dbo.attendancewhere title = 'agent'AND NOT EXISTS(SELECT * FROM dbo.attendance_non) Poor planning on your part does not constitute an emergency on my part. |
 |
|
|
erickcm18
Starting Member
2 Posts |
Posted - 2011-02-04 : 12:22:35
|
| Sorry, I forgot to mention that the profile is in other table called dbo.employees.So, the title is in dbo.employees.If the employee has "agent" in dbo.employees select the view dbo.attendance IF NOT select dbo.attendance_nonHow can I do thatNOTE: dataguru1971 thanks for the informationthanks |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-04 : 12:27:08
|
| IF Exists(select 1 from dbo.employees where <employees has 'agent')SELECT * from dbo.attendanceELSESELECT * from dbo.attendance_nonJimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|