June 28, 2013 at 11:16 am
Can anyone provide me a short example of how to implement this? I am not able to do this and need to.
Any and all help will be greatly appreciated!! Back to Google!
June 28, 2013 at 11:32 am
you want to use raiseerror as a progress indicator from some dynamic SQL, is that it?
here's one example that would be appriate in a cursor loop, does this help?
--print error immediately in batch
declare @i int,
@err varchar(100)
--set @i=1
while 0=0
begin
SET @err = 'Progress So Far: Step ' + convert(varchar(30),ISNULL(@i,1)) + ' completed.'
raiserror (@err,0,1) with nowait
waitfor delay '00:00:02'
set @i=ISNULL(@i,1) + 1
end
RAISERROR ('Duplicate Records',16,1)
Lowell
June 28, 2013 at 1:51 pm
Or do you want to use RAISERROR with a message that contains a variable string?
Example:
SELECT @intCount = COUNT(*)
FROM table_name
WHERE code = @passed_code;
IF @intCount > 0
BEGIN
SET @strErr = 'Error: Parameter ' + @passed_code + ' not in table table_name';
RAISERROR(@strErr, 16, 1);
RETURN;
END;
We're just guessing at your intent here. If we've missed it, could you provide something else to go on?
July 1, 2013 at 6:11 am
Lowell and Ed,
Thanks for the replies, I will try to better explain what I am doing and what I am looking for.
What I am doing: I have cursor that is looping over all of the Linked Servers I have set up on my server and inserting into a local table on my server. I am using Dynamic SQL for my INSERT INTO statement.
What I am trying to do: If for some reason, there is an error within the INSERT, I want to use RAISERROR to return the error back to my SQL Agent job, close the cursor and deallocate the cursor.
My apologies as well for the late reply, I was out of town all weekend without much access to Internet. Please let me now if I am not doing a very good job of explaining myself.
Thanks Again for your help!
July 1, 2013 at 6:50 am
Could you please post your sql which builds dynamic SQL your INSERT INTO statement.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy