Home All Groups Group Topic Archive Search About

Set default value from another table?

Author
14 Jul 2005 3:29 PM
MartyNg
I have a field in a table which I need to set a default value for. The
default value needs to be a string concatenation of two fields from a
DIFFERENT table. Anyone know how to do this? Thanks!

SQL Server 2000.

Author
14 Jul 2005 3:31 PM
Aaron Bertrand [SQL Server MVP]
Do you really need to store this?  Why can't you generate that from a VIEW
or directly in the SELECT statement?



Show quote
"MartyNg" <Mart***@gmail.com> wrote in message
news:1121354940.832668.123400@g47g2000cwa.googlegroups.com...
>I have a field in a table which I need to set a default value for. The
> default value needs to be a string concatenation of two fields from a
> DIFFERENT table. Anyone know how to do this? Thanks!
>
> SQL Server 2000.
>
Author
14 Jul 2005 3:54 PM
MartyNg
The table that the default needs to go into is a major table and feeds
into several other systems. Is there not an easy way to grab this data?
Author
14 Jul 2005 4:06 PM
--CELKO--
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications.  It is very hard to debug code when you do not let us
see it.
Author
14 Jul 2005 5:15 PM
David Portas
If the default may change (I assume that's why it's in a table) but you
need to preserve the historical values then do the join as part of the
INSERT. If the default doesn't change or you don't need to preserve
history then the column is redundant - drop it and use a view. The fact
that it feeds several other systems shouldn't stop you doing that.

--
David Portas
SQL Server MVP
--
Author
14 Jul 2005 5:02 PM
--CELKO--
>>  have a field [sic] in a table which I need to set a default value for. The default value needs to be a string concatenation of two fields [sic] from a DIFFERENT table. <<

No.  The idea is absurd.  That would allow the DEFAULT value to be
changed during execution.  That would destroy insertions, updates and
DRI actions.  You do not seem to understand what a DEFAULT does.

Rows are not records and fields are columns.

If you need to reference a second table, then use a VIEW.
Author
14 Jul 2005 5:03 PM
Aaron Bertrand [SQL Server MVP]
> Rows are not records and fields are columns.

Joe!  You just said fields are columns!  :-)
Author
14 Jul 2005 6:30 PM
--CELKO--
Typo!  Typo!  Typo!   The dog bit my fingers.  Really.  I have bandages
on both hands from breaking up a dog fight manually last week.  Let's
put the new rule up there with "Do not fry bacon without a shirt."
Author
14 Jul 2005 8:43 PM
Steve
I bet I know why they were fighting.  One dog said to the other dog "let's go
running in that column".  They other dog replied "columns are not fields...."



Show quote
"--CELKO--" wrote:

> Typo!  Typo!  Typo!   The dog bit my fingers.  Really.  I have bandages
> on both hands from breaking up a dog fight manually last week.  Let's
> put the new rule up there with "Do not fry bacon without a shirt."
>
>
Author
15 Jul 2005 6:55 PM
--CELKO--
>> One dog said to the other dog "let's go running in that column".  They other dog replied "columns are not fields...." <<

LOL!!

AddThis Social Bookmark Button