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

  • SEARCH
  • Home
  • 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 6531421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:52:35+00:00 2026-05-25T09:52:35+00:00

enter code hereIn my SQL Server database I have my address information for the

  • 0

enter code hereIn my SQL Server database I have my address information for the subNumber (e.g. Unit 802) and the streetNumber (e.g. 242 Elizabeth Street) stored separately.

I need to display these as one (i.e. 802/242 Elizabeth Street) if the subNumber contains a value, otherwise just return the streetNumber if it does not.

I’ve been working toward a solution using IF ELSE and a foreach loop after accessing the data through LINQ – but I’m stuck after the point where I have completed the loop. I would also be happy to do this with a SELECT Stored Procedure in SQL – open to suggestions!

DataClassesDataContext dc = new DataClassesDataContext();

var recent = from p in dc.Properties
             orderby p.modtime descending
             where p.status == "Current"
             select new
             {
                 rsub = (p.subNumber).ToString(),
                 rnumber = (p.streetNumber).ToString(),
                 rstreet = p.street,
                 rsuburb = p.suburb,
                 rurl = p.propertyURL,
             };

foreach (var home in recent)
{
    if (string.IsNullOrEmpty(home.rsub))
    {
        string rnum = home.rnumber;
    }
    else
    {
        string rnum = home.rsub + "/" + home.rnumber;
    }
}

recentrepeater.DataSource = recent;
recentrepeater.DataBind();

Yahia gave the best option in c# – this is the SQL solution I have finally ended up with:

ALTER PROCEDURE GetPropertyShort

AS
SELECT TOP 5 ISNULL(convert(varchar(5), subNumber) + '/' + convert(varchar(5), streetNumber), convert(varchar(5), streetNumber)) as Number, street, suburb, propertyURL, modtime
FROM Property
ORDER BY modtime DESC
  • 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-25T09:52:35+00:00Added an answer on May 25, 2026 at 9:52 am

    try

    var recent = from p in dc.Properties
            orderby p.modtime descending
            where p.status == "Current"
            select new
           {
                rsub = (p.subNumber).ToString(),
                rnumber = (p.streetNumber).ToString(),
                rnum = string.IsNullOrEmpty((p.subNumber).ToString()) ? (p.streetNumber).ToString() : (p.subNumber).ToString() + "/" + (p.streetNumber).ToString(),
                rstreet = p.street,
                rsuburb = p.suburb,
                rurl = p.propertyURL,
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

enter code here I have a table on SQL server 2005 with bigint primary
enter code here Hi All, I have a simple windows service application that connects
enter code here I have the following code to build select menus dynamically: $j(#id).load('create_menu.cgi',
enter code here I have a TabControl on a Form and in the TabPages
I have the following entry in my c:\Oracle\product\11.1.0\network\ADMIN\TNSNAMES.ORA file. enter code here pvtest.world =
I let user enter some code in my Flex3 (Flash 10) app and I
When I enter 9:00 into the Start control, and 16:00 into Finish; the code
When trying to enter a SQL query with parameters using the Oracle OLE DB
When I enter an object into the DB with Linq-to-SQL can I get the
I have a couple of classic ASP pages that require a user to enter

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.