Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default Value for Column

Status
Not open for further replies.
Apr 11, 2003
50
US
I have a set of tables that Gather totals depending on the type of funding (eg. Y, N, M). For those totals I gather that have a null value, I want a 'T' placed in the column next to the count. My question is HOW DO I DO THIS? I am so agitated cause I cannot figure it out.
 
create default funding_default AS 'T'
sp_bindefault funding_default , 'tablename.columname'


But this has to be defined before inserting value.So if the column value is null due to default it will become 'T'
 
Is this the sort of thing you need to do?

select
isnull(fundtype,'T') as fundtype
,sum(funds) as funding
from
tabFund
 
Claire,
Do I do that in T-SQL? And Do I have to do it once for each table that I need this or can I do it for all tables in the same statment?
 
I misread your initial question. I'm up to speed now I hope.

You need to run the second part of Claire's script for each table.

create default funding_default AS 'T' -- run once
sp_bindefault funding_default , 'tablename.columname' -- for each table

Note that: Insert or update statements that explicitly set the value of the funding type column to null will effectively side-step this mechanism. As Claire said, all existing nulls will remain as nulls - only future inserts and updates will be affected by the default.

Hope this is more helpful than my last post.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top