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.
| Author |
Topic |
|
danasegarane76
Posting Yak Master
242 Posts |
Posted - 2007-08-21 : 09:31:59
|
| I need to insert default value if the local variable is null.The following gives error.Could any one help on this....create table testdefault (id int,name varchar(10),required bit default 0)insert testdefault values (1,'aabaxq',default) --no errordeclare @req varchar(1)insert testdefault values (1,'aabaxq',coalesce(@req,default)) -errorordeclare @req varchar(1)insert testdefault values (1,'aabaxq',isnull(@req,default))--error |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-21 : 09:42:11
|
If you know the default value is zero, use that.insert testdefault select 1,'aabaxq',isnull(@req,0) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
danasegarane76
Posting Yak Master
242 Posts |
Posted - 2007-08-21 : 09:45:47
|
| Some times I know the default.But Some times I dont know ?is there any other method ?Shall i try like this ?select column_default from information_schema.columns where table_name='testdefault' and column_name='required' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 01:48:03
|
| If @var is nullinsert testdefault(col1,col2) values (1,'aabaxq')elseinsert testdefault(col1,col2,col3) values (1,'aabaxq',@var)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|