I have a form with some fields including address fields. There is one field FormattedAddress which I have to update with some fields concatenated for an address label.
What would be the best way to address this kind of situation?
So far I am testing in the BO_FieldPropertyChanged event, but I then have to filter this event for the list of fields that will participate in the concatenation format. Just wondering if I am in the correct place or there is any other way to do this?
Thanks!
Thanks a lot for your input.
So far this information will not be used outside the database. Basically this is a VFP project I am converting to .NET and of course some logic will need to be changed and this is one of those
The idea is to be able to use this information in some custom printing like an Invoice/Receipt and a label, so I don't have to be recalculating this data and yes, I agree with all of you that a Custom Field is the winner here.
That is a good point on the DB side, but I would probably just create a UDF or stored proc to return the formatted value versus creating a table. This way you don't have any additional overhead hitting the database each time you call the method. If you create a UDF, the you can include it as an AS column in a SELECT query.
Example UDF for SQL Server to format the address DB side
AS
BEGIN -- Declare the variables that will be used to build the formatted address DECLARE @returnAddress NVARCHAR(1024); DECLARE @address NVARCHAR(150); DECLARE @city NVARCHAR(60); DECLARE @state NVARCHAR(128); DECLARE @postal NVARCHAR(20);
-- Select the values into the SELECT @address = cust_Address1, @city = cust_city, @state = cust_state, @postal = cust_postal FROM Customers WHERE cust_pk = 1;
-- Format the return value SET @returnAddress = @address + CHAR(13) + @city + ', ' + @state + ' ' + @postal;
-- Return the formatted address RETURN @returnAddress; END
Including the UDF in a query
That would be the TRUE test on your data. Also, it can be a really good idea to add some indexes on those fields as well.