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 |
|
ssknoah
Starting Member
1 Post |
Posted - 2007-12-10 : 02:42:58
|
| hi alli am a beginner, i have written an insert stored procedure.i need my SP to check for the ID field whether the data is already present.pls help ,me.ALTER PROCEDURE [dbo].[SP_SaveGroupClassification]@SubGroupName nvarchar(50),--@GroupId int,@ParentId int,@ClassType nchar(2),@RootId intasbeginINSERT INTO GroupClassification(GroupName, ParentId, ClassType, RootId)VALUES (@SubGroupName,@ParentId,@ClassType,@RootId)endreturnHere i need to check the value in (@SubGroupName not to be repeated.it is my key field.thank ussk |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-10 : 02:47:52
|
[code]INSERT INTO GroupClassification(GroupName, ParentId, ClassType, RootId)SELECT @SubGroupName,@ParentId,@ClassType,@RootIdWHERE not exists (select * from GroupClassification where GroupName = @SubGroupName) [/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-12-10 : 02:48:07
|
| Change the INSERT like this:-IF NOT EXISTS(SELECT * FROM GroupClassification WHERE GroupName=@SubGroupName)BEGIN INSERT INTO GroupClassification(GroupName, ParentId, ClassType, RootId)VALUES (@SubGroupName,@ParentId,@ClassType,@RootId)END |
 |
|
|
|
|
|
|
|