Getting Started with Adobe After Effects - Part 6: Motion Blur
Ask
Ask questions, discuss or help others by answering
Related Posts · View All
SQL Server 141
TSQL 75
SSRS 70
SSIS 66
XML 54

Top Categories · View All
SQL Server 141
TSQL 75
SSRS 70
SSIS 66
XML 54

Error Message

Aug 9 2012 12:00AM by abhIShek BandI   

I have 2 categories, success true or false,

when success is true , i need to display nearly 10 select statments, when its false, i ll display select 'false' as success.

but, if the success is true and while am running 10 result sets, 8th select statement through the error. at that time also i need to display select 'false' as success..

but am getting 7 select statements,after that getting error message. how can i solve this? I tried with, transaction,try catch,SET XACT_ABORT, but those are not giving as i expected Sample Query:

    create proc #a
    @id int
    as
    declare @name varchar(100)
    select @name = OBJECT_NAME(@id)
    
    if @name is null
    begin
        select 'false' success
    end
    else
    begin
        select 'true' success
    
        select 1
    
        select 2
    
        select 3/0
    end
    
    go
    
    --[success case:] 
    select 'result set 1'
    exec #a 1
    
    --i want to display the success:false in below senario
    select 'result set 2'
    exec #a 3

in result set 2 , i want to display select 'false' as success

Submitted under: Microsoft SQL Server · TSQL ·  ·  · 


abhIShek BandI
104 · 2% · 503

3 Replies

  • You can wrap that statement into a TRY CATCH block to achieve this (if you are on SQL Server 2005 or above)

    ALTER PROC aa
    (
    	@id int
    )
    AS
    DECLARE @NAME VARCHAR(100)
    SELECT @NAME = OBJECT_NAME(@ID)
    
    IF @NAME IS NULL
    BEGIN
    	SELECT 'FALSE' SUCCESS
    END
    ELSE
    BEGIN
    	SELECT 'TRUE' SUCCESS
    
    	SELECT 1
    
    	SELECT 2
    
    	BEGIN TRY
    		SELECT 3/0
    	END TRY
    	BEGIN CATCH
    		SELECT 'FALSE'
    	END CATCH
    END
    
    GO
    

    Is this what you are looking for?

    commented on Aug 9 2012 1:21PM
    Jacob Sebastian
    1 · 100% · 32002
  • No, sir.

    if any error occurred, i need to display only select 'false' as success. means only one select statment.

    if all the select statments executed successfully , then only i need to display all the statments, or else only false.

    Thanks in Advance

    commented on Aug 10 2012 4:32AM
    abhIShek BandI
    104 · 2% · 503
  • Please don't think that I am rude, I would certainly consider this to be a bad design. This adds unwanted complexity. To achieve this you need to first execute all queries, capture results into temp tables, and finally decide to serve it to the client based on the result of the whole batch.

    Instead of adding this weired complexity to the database code, the client application can easily do it.

    If you still want to do it this way, execute each statement within a try catch block and capture the output into temp tables. Finally, if all statements succeed, then serve data from the temp tables. If any statement fails, then serve "false"

    commented on Aug 10 2012 6:06AM
    Jacob Sebastian
    1 · 100% · 32002

Your Reply


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]