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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using Computed Column in SQL 2005

Author  Topic 

clinton_eg
Yak Posting Veteran

60 Posts

Posted - 2010-06-10 : 08:33:27
Hi

Im trying to use a the Computed Column option in Column properties in Microsoft SQL Server Management Studio

Im want to create a unique ID by combining the value of two existing columns in a Table

Example:
Column 1 = datetime
Column 2 = varchar(30)
I want column 3 to create a unique ID by adding Column1 and Column2.
So when i upload data into the table using a DTS or SSIS package, Column 3 gets populated with the required Unique ID.

I get an error when i try to add in the (Formula) field under Computed Column Specification:
Column 1 + Column 2

Error: Error validating the formula for column 'Column 3' Do you want to cancel your changes?

Im sure im not doing something right . Please help

Ewan Gilby

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-10 : 08:38:15
you need to convert Column 1 to string first before concatenate with column 2

check out convert() in BOL


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

clinton_eg
Yak Posting Veteran

60 Posts

Posted - 2010-06-10 : 09:29:06
i tried

convert(varchar(20),[Column 1],101)+[Column 2]

but still get the error

Ewan Gilby
Go to Top of Page
   

- Advertisement -