October 24, 2008 at 3:29 am
I would like to run a T SQL script that looks at the data within a table and specific column and generate an Error message if there is a Null Value present...
Can this be done?
October 24, 2008 at 3:35 am
This should be what you are looking for
If Exists(
Select top 1 * From Tab where Col is Null
)
Begin
Raiserror( msg.......)
End
October 24, 2008 at 3:35 am
This should be what you are looking for
If Exists(
---Check if such a row exists
Select top 1 * From Tab where Col is Null
)
Begin
--use the Raiserror function
Raiserror( msg.......)
End
October 24, 2008 at 3:38 am
Check if that will help you.
use tempdb
go
create table #t1 (
col1 int,
col2 int
)
insert into #t1 values (1, 1)
insert into #t1 values (2, null)
if exists (select * from #t1 where col2 is null)
raiserror('There is null value in col2',16,1)
drop table #t1
October 24, 2008 at 3:46 am
Thanks for your help. I seem to have something basic working at the moment that I can now build on. I am a complete newbie to this stuff. C an I just ask you in your raiseerror you put the error message followed by ,16,1)
what does the 16 and 1 do?
October 24, 2008 at 3:51 am
16 means a severity level.
1 means a state.
that's from BOL:
If the same user-defined error is raised at multiple locations, using a unique state number for each location can help find which section of code is raising the errors.
October 24, 2008 at 4:39 am
Thank you for you help...
I seem to have got that working well now
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply