473,668 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default value being a concatenation of other columns

Hello all,

Does anybody know if it is possible to set the default value of a
field to equal the concatenation of 2 other fields?
I.E.
Field 1 = 123
Field 2 = 345
Field 3 = (Field1 + Field2) = 123345

This is easy enough to do using a stored procedure, but I'm trying to
use the import tool and so need to do the concatenation by default.

Many thanks,
Drew.

Jul 19 '07 #1
1 6367
Drew (an******@gmail .com) writes:
Hello all,

Does anybody know if it is possible to set the default value of a
field to equal the concatenation of 2 other fields?
I.E.
Field 1 = 123
Field 2 = 345
Field 3 = (Field1 + Field2) = 123345

This is easy enough to do using a stored procedure, but I'm trying to
use the import tool and so need to do the concatenation by default.
No, but you can define a computed column:

CREATE TABLE nisse (kalle int NOT NULL,
lisa int NOT NULL,
putte AS kalle + lisa)

Of course, if you need to update the columns independently of each
other, this is not any feasible solution.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3284
by: Programmer | last post by:
Hi All Here is my problem I'm using a SQLDataAdapter and DataSet I use the method FillSchema(myDataset, SchemaType.Source) The problem is that when i Check the default Values of the Dataset i can see that the DefaultValue of the columns is system.dbnull!!!! But in SQL Server i have put as default values in a bigint field the '0' and
10
6962
by: serge | last post by:
I am doing a little research on Google about this topic and I ran into this thread: http://groups.google.com/group/microsoft.public.sqlserver.programming/browse_thread/thread/63cce060ff152dcc/1dc13d4ee6758966?lnk=st&q=difference+constraint+sql+defaults&rnum=14#1dc13d4ee6758966 I read SQL Server MVP Louis Davidson's post saying: "Actually they are more likely to drop the concept of bound defaults. Constraints are the standard way to do...
5
2677
by: serge | last post by:
How can i enter Default Values of " " to all the columns of type character of all the tables (excluding system tables) and Default Values of 0 of all columns of type numbers. Excluding all primary key columns. Thank you
5
1845
by: | last post by:
i have three columns hrs_due, hrstaken, and totalhrsneeded i need the default value of hrs_due to = totalhrsneeded - hrstaken the data type of all is number>long integer, and i try to key =- into the default value of hrs_due but it will not accept it can anyone plz help?? thanks
4
10082
by: Brian Brane | last post by:
I have properties that wrap DataRow columns as in: public int aNumber { get{ return m_DataRow; } set{ m_DataRow = value; } } If the column happens to contain DBNull, I get a cast exception since DBNull cannot be converted to int. I wrote the following method that looks up the column's data type and if it is a ValueType, returns the default value for the ValueType.
1
2728
by: tg.foobar | last post by:
my setup: visual studio 2005 sql server 2000 i'm using a dataset (used to be called typed dataset in 2003), where i use the MSDataSetGenerator to create a class for me based on the scheme of my SQL server. This schema doesn't include the default values that are defined in the SQL server. It's setting all the default values to NULL. is thre an easy way to get around this? for example, i have a
3
13658
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or define a default value to be used? I want to think through the repercussions of this decision before I get into production.
0
1160
by: Drew | last post by:
Hello all, Does anybody know if it is possible to set the default value of a field to equal the concatenation of 2 other fields? I.E. Field 1 = 123 Field 2 = 345 Field 3 = (Field1 + Field2) = 123345 This is easy enough to do using a stored procedure, but I'm trying to
0
1278
by: piercy | last post by:
Hi, Im tyring to display a dataGridView with comboBoxes on about 5 of the fields. This table is basically permissions to certain parts of my program. In the database i just store a 1 or a 0 (access or no access). Now obviously to the user i want this to be displayed as text. Now currently i am creating the columns manually and using the cell changed event to do the updating. This is quite long winded and if possible i would like a simpler...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.