question

koptastic69 avatar image
koptastic69 asked

Calculated columns in SQL Server 2008

I'm trying to create a column in a view in SQL server 2008. The column is to be generated from two fields in the table, date and an account number, in the format dd.mm.yyyynnnnnnnn where nnnnnnnn is the account number. I've prototyped it in Access and it works fine, but I can't get it to work here in SQL server. I've tried the following;

SELECT     charGroup, charAccID, intAccountNo, charType, charBankCode, charCurr, dteDate, charAsAt, monAmount, charTLACode, charChequeNo, charStatus, charDescription, 
                      CONVERT(VARCHAR(50), dteDate, 104) AS VARCHAR + intAccountNo AS GENKEY
FROM         dbo.tblStatementHold

Any ideas?

sql-server-2008computed-column
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Matt Whitfield avatar image
Matt Whitfield answered

Try this:

SELECT     charGroup, charAccID, intAccountNo, charType, charBankCode, charCurr, dteDate, charAsAt, monAmount, charTLACode, charChequeNo, charStatus, charDescription, 
                      CONVERT(VARCHAR(50), dteDate, 104) + CONVERT(varchar(50), intAccountNo) AS GenKey
FROM         dbo.tblStatementHold
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.