| 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? |
 |
|
|
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.. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-16 : 01:07:18
|
| use if statementIF(@DIM IS NOT NULL)BEGININSERT INTO DUMMY_MASTER(DD,DD1,DD2,DD3)VALUES(DD,DD1,DD2,DD3)INSERT INTO DUMMY_DETAIL(DD,DIM)VALUES(@DD,@DIM)ENDELSE SELECT 'INSERTION Failed' |
 |
|
|
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... |
 |
|
|
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 |
 |
|
|
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 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-16 : 05:33:22
|
| in your table column, usingALTER TABLE <tablename> ADD <ColumnName> <datatype> NOT NULL |
 |
|
|
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 tableALTER TABLE DUMMY_DETAIL ALTER COLUMN DIM VARCHAR(20) NOT NULL |
 |
|
|
|