I have a table lets call P (as an example)
P has the following usefull fields:
-------------------------------------------------------------------------------------------------
P_ID | CategoryID | Pre-Text | RevNumber | ComputedColumn1
-------------------------------------------------------------------------------------------------
Now I want [ComputedColumn1] to be a string concatination of [Pre-Text]+(thing)+[RevNumber]
Where (thing) is a value from the [Name] column in my Category table, whos entry has the same ID number as the stored CategoryID.
Now I know how to do this with a select statement, but I was hoping to have that [ComputedColumn1] hold the value(or the formula to reference the value)
With a select statement:
Expand|Select|Wrap|Line Numbers
- SELECT
- (P.[Pre-Text] + C.[Name] + P.RevNumber ) as [MyColumn]
- FROM P, Category
- WHERE
- Category.CID=P.CategoryID
Expand|Select|Wrap|Line Numbers
- CREATE function MyFunc(@A_ID AS int)
- RETURNS varchar(50)
- AS
- RETURN (SELECT Name FROM Category WHERE Category.CID= @A_ID)
- go
Expand|Select|Wrap|Line Numbers
- Msg 170, Level 15, State 31, Procedure eatit, Line 4
- Line 4: Incorrect syntax near 'RETURN'.
Any thoughts for how to do this? (Or a completely differnt and better way to do it?)