Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 null error

Author  Topic 

wormz666
Posting Yak Master

110 Posts

Posted - 2009-02-15 : 22:43:28
assume i have a parameters


<condition>
i have 3 insert statement in a relational table
i pass a parameter in the 2nd table will all value is null
it save on the 2 table


i want that will it pass a null value, in one of the table it will prompt an error

and it will not save on the other 2 table.....


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-15 : 23:16:50
sorry cant understand what you're asking for. can you explain with some sample data?
Go to Top of Page

wormz666
Posting Yak Master

110 Posts

Posted - 2009-02-16 : 01:02:00
DECLARE @DD VARCHAR(20)
DECLARE @DD1 VARCHAR(20)
DECLARE @DD2 VARCHAR(20)
DECLARE @DD3 VARCHAR(20)
DECLARE @DIM VARCHAR(20)

INSERT INTO DUMMY_MASTER
(DD,DD1,DD2,DD3)
VALUES(DD,DD1,DD2,DD3)
INSERT INTO DUMMY_DETAIL
(DD,DIM)
VALUES(@DD,@DIM)

WHAT I MEAN IF I PASS A PARAMETER IN THE SECOND TABLE THAT THE @DIM PARAMERETER IS NULL,
THEN THE FIRST SQL STATEMENT IN NOT EXECUTE......

COULD IT BE POSSIBLE??
HOW WILL I SUPPOSE TO DO IT??
PLEASE HELP....

THANK YOU IN ADVANCE..
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-16 : 01:07:18
use if statement

IF(@DIM IS NOT NULL)
BEGIN
INSERT INTO DUMMY_MASTER
(DD,DD1,DD2,DD3)
VALUES(DD,DD1,DD2,DD3)
INSERT INTO DUMMY_DETAIL
(DD,DIM)
VALUES(@DD,@DIM)
END
ELSE
SELECT 'INSERTION Failed'
Go to Top of Page

wormz666
Posting Yak Master

110 Posts

Posted - 2009-02-16 : 01:11:09
how about if the i have a multiple insert statement, i have to specify the primary and foriegn key..

i want that i will not have to specify them all,it will automatically execute and error...

i tried raiserror back.. but i have the error get...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-16 : 01:54:58
then create a NOT NULL constraint on your DIM field of DUMMY_DETAIL so that it raises error automatically when you insert null value
Go to Top of Page

wormz666
Posting Yak Master

110 Posts

Posted - 2009-02-16 : 04:10:40
how will i create a not null constraint... where should i create it
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-16 : 05:33:22
in your table column, using

ALTER TABLE <tablename> ADD <ColumnName> <datatype> NOT NULL
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-16 : 05:42:55
alter ur column if ur not having any data in ur table
ALTER TABLE DUMMY_DETAIL ALTER COLUMN DIM VARCHAR(20) NOT NULL
Go to Top of Page
   

- Advertisement -