Best practice for creating a mask?

  • I have a table that has a few fields that will normally appear together, along with some text, but that I want to keep as discreet fields. What is the best way to persist this?

    I have these fields, all nVarChar(10):

    FIELD1

    FIELD2

    FIELD3

    FIELD4

    On both input and output, I will almost invariably consider them together, like so:

    [FIELD1]/[FIELD2]/[FIELD3]/[FIELD4]

    In other words, I would like to refer to them as "MyFields" and have them appear like so, with the slashes between them, both during data entry and for Reporting Services.

    Ie: In reporting services I want a field called "MyFields" which has that concatention.

    Does this call for a Calculated Field in the schema? A view? Something else?

    I'm a newbe.

    Thanks,

    "What I lack in youth I make up for in immaturity!"
    Please visit my music site at http://woundedego.com

  • a calculated field would do the trick: add a column to your table like this:

    ALTER TABLE MYTABLE ADD

    MYFIELD AS COALESCE(FIELD1,'') + '/'

    + COALESCE(FIELD2,'') + '/'

    + COALESCE(FIELD3,'') + '/'

    + COALESCE(FIELD4,'')

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for the answer.

    I apologize for the dup posts. I can't seem to avoid it. And I tried to delete it twice, but it would not delete!

    "What I lack in youth I make up for in immaturity!"
    Please visit my music site at http://woundedego.com

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply