May 2, 2003 at 7:21 am
Hello,
Maybe somebody knows the anser.
We are using C# to fill a database, how do we get the database defaults into the recordset that we want to add.
i.e. We want to get the default columns for a particulartable out of SQL.
Is there an easy way to do this
May 2, 2003 at 10:45 am
Here are two approaches you might use. Since I don't know if you are using an INSERT statement directly or a stored procedure, please adjust the response accordingly.
1. Leave out the column from the INSERT statement where you want the default value. If you are using a stored procedure, you would probably need to use dynamic SQL and either leave out the column or use the word DEFAULT.
2. Read the default information from the syscomments table. You can get it this way...
SELECT def.text
FROM sysobjects so (NOLOCK)
INNER JOIN syscolumns sc (NOLOCK) ON sc.id = so.id
LEFT OUTER JOIN syscomments def (NOLOCK) ON def.id = sc.cdefault AND def.colid = 1
WHERE so.name = <table name> AND so.Type = 'U' AND sc.name = <column name>
Guarddata-
May 13, 2003 at 4:08 am
Sorry for beeing late at this.....
The problem is i get something like :
create default [defstatus] as '00 '
And I Really want the Value '00 '
Because what if a default is a function ???
( or is this not possible )
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply