Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:26:14+00:00 2026-05-27T17:26:14+00:00

currently I have to change a view, a big part of the view code

  • 0

currently I have to change a view, a big part of the view code looks like this:

CAST('My_Tag_' + CASE 
        WHEN FieldX isnull
            THEN ''
        WHEN FieldX = '123'
            THEN 'some_number'
        WHEN FieldX = 'abc'
            THEN 'some_text'
        ELSE 'strange' ) AS VARCHAR(128) AS myField
)

Just a chunk of code, that puts together a string (the code itself doesn’t even matter right now, I have like 50 other examples, where I have a lot of code replication). Now I have exact the same code for 30 more fields in the view, just the ‘My_Tag_’ and FieldX is changing. If this would be C#, I would just write a little helper function.
Of course I could write a function here, too. But as this is a bigger project with a lot of tables, views, etc, I would have hundreds of functions soon.

Now I am pretty new to SQL and normally my home is the OOP-world. But there has to be a solution to avoid code replication and to avoid having hundreds of helper functions in the database?

What’s best practice in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:26:15+00:00Added an answer on May 27, 2026 at 5:26 pm

    The best practice may be to create a user defined function.

    The arguments would be the fields that change and it would return the intended value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
I currently have an asp.net page, that takes in the data from this view
I currently have a link that launches a telnet link like this <h:outputLink value=telnet://1.2.3.4>
Anything I have tried didn't work. Currenly I have following code to change asp.net
Currently have password protection on my main and sub directories, however I'd like to
I currently have an EF class that is backed by a database view (joining
I currently have an option that allows a user to change the display order
I have an 'account' view, where a user can change his email, name, and
I currently have Spring configured to use HSQL, but I would like to use
I currently have an application that is storing around 10 variables per android view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.