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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Database selection

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.attendance
2- dbo.attendance_non

Basically my question is what SQL script can I use to indicate:

Select *
From dbo.attendance
where 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.attendance
where title = 'agent'
AND NOT EXISTS(SELECT * FROM dbo.attendance_non)








Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

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_non

How can I do that

NOTE: dataguru1971 thanks for the information

thanks
Go to Top of Page

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.attendance
ELSE
SELECT * from dbo.attendance_non

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -