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 |
M_N_M
Starting Member
21 Posts |
Posted - 2010-09-23 : 14:09:42
|
Hello,is it possible to use a "variable" default value on a field.I'll try to make it clear with an example.I have a table "x" with the following fields:company_id intfield1 char(20)field2 varchar(100)From within my application, I'm doing the following insert query:INSERT INTO x (field1, field2) VALUES (?value1, ?value2)I want the field "company_id" to be filled from a value that comes from a temporary table (company_id is either 1 or 2, based on the user that is logged in...)I know you can use "functions" as a default value of a field BUT in functions you can't use temporary tables :-(Is there a workaround? (is there no such thing as "user global variables" like @@ROWCOUNT ?)If no, I need to use "INSTEAD OF" triggers but I don't like them and I try to avoid them as much as possible...Thanks in advance |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
M_N_M
Starting Member
21 Posts |
Posted - 2010-09-23 : 15:09:51
|
it's not that easy. This is an example for one query but I need to do it for the whole application (> 1.000.000 queries)That's the reason why I want to use a default based on a temp table.. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|