-
Try Catch
Hi
for MS SQL 2000
how can I do ?:
INSERT INTO [Users] (Name)
SELECT Names FROM OtherUsers
I am having an UNIQUE INDEX on [Users].Name
how can I avoid an error ?
if the [Users].Name allready exists I want to jump over the error and keep on inserting
thank you for helping
-
Try code like:
INSERT INTO [Users] (Name)
SELECT Names FROM OtherUsers
where OtherUsers.Names not in (select Name from Users)
-
There is no TRY CATCH in SQL 2000, the sql batch terminates if it encounters unique key violation.
-
is there any way to do the same thing than a try catch ?
if error <> 0 then no matter !
thak you rmiao it works but I am looking for a error handling to jump over errors
-
begin tran
INSERT INTO OTHERUSERS SELECT 'b'
IF @@ERROR=2601
BEgin
print 'rollback'
ROLLBAck
END
else
begin
print 'commit'
commit
end
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|