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
 Help me

Author  Topic 

ducletan
Starting Member

25 Posts

Posted - 2010-12-06 : 03:42:33
Department_ID nvarchar(2)
Possition_ID nvarchar(2)

give me code to solve : with each Department_ID
have only <=1 Department manager (Possition_ID='00')

thanks

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-12-06 : 03:47:20
SELECT Department_ID FROM YourTable
WHERE Possition_ID = '00'
GROUP BY Department_ID HAVING COUNT(Possition_ID) <= 1


Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

ducletan
Starting Member

25 Posts

Posted - 2010-12-06 : 04:03:23
Thanks,but give me trigger or rule... to solve the problem
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-12-06 : 04:06:38
Welcome

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-12-06 : 04:09:25
What is the need for trigger or rule ?
For select Query ?

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

ducletan
Starting Member

25 Posts

Posted - 2010-12-06 : 20:14:27
I want: on my table (Department_ID nvarchar(2),Possition_ID nvarchar(2))
never occur: exists

SELECT Department_ID FROM MyTable
WHERE Possition_ID = '00'
GROUP BY Department_ID HAVING COUNT(Possition_ID) >= 2

Help me the way
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-12-06 : 20:35:05
use UNIQUE Constraints


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ducletan
Starting Member

25 Posts

Posted - 2010-12-06 : 20:48:13
"use UNIQUE Constraints"
Help me more clearly,thanks
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-12-06 : 22:54:04
quote:
Originally posted by ducletan

"use UNIQUE Constraints"
Help me more clearly,thanks



For example lets say that your existing table structure is as follows:
Create table Test
(
Srno Int identity,
Department_ID nvarchar(2),
Possition_ID nvarchar(2)
)


Now you add a unique constraint on both the column. This will make sure that the combination key of Department_ID & Possition_ID is unique. You can read more on unique constraint in the link given by khtan.
Alter table Test
Add constraint UK_Test Unique (Department_ID, Possition_ID)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-12-07 : 07:17:32
quote:
Originally posted by ducletan

"use UNIQUE Constraints"
Help me more clearly,thanks



follow that link. there are clear explanation and examples in there.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -