Link to home
Start Free TrialLog in
Avatar of dinesh_bali
dinesh_bali

asked on

Select Query does not display record if field has null value and Raise Exception Stored Procedure

Hi,

I am working on MSSQL 2005

How can we use Raise Error in Stored Procedure

My query is not giving me record I did not understand the reason

In table t1 I have field status

In status filed there can be different different values like

ERROR
INSERTED
or this field (status) field can be NULL

Now when I write select query

select * from t1 where status <> 'ERROR' -- (Not Equal to ERROR)

then this does not display records where status is null

What is the reason, what I have to do so that it works

Many Thanks
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image


select * from t1 where status <> 'ERROR' Or Status Is Null

Using a null value in any operator test such as = > < <> etc except for the Is operator results in a Null which doesn't equate to either True or False so is excluded automatically.

If you need to include Nulls then you need to use the Is operator to test for them.
Avatar of dinesh_bali
dinesh_bali

ASKER

Hi,

Thanks for your help

There was one more issue that
How can we use Raise Error in Stored Procedure?

Many Thanks
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HI,

Thanks for all your co-operation

I am sorry , I am week, can you please guide me that where I should place it

or at the end

And what exactly you have written

In Exception this will write Test

I am sorry for troubling you

Many Thanks again