sql select statement that only displays some of the colums

Posted on 2011-10-24
Last Modified: 2012-08-13

I need to run a query on a table that several of the columns but only display the first name last name and office number in a dropdown list. I need to retrieve the other columns because the additional fields will need to be posted to a new table based on the users selection from the dropdown box. I am having trouble with the query. This is what I have:
Select LastName + ' ' + FirstName + ' ' + 'office ' + ' ' + Company AS Agent, AssociateCell,Email
From tbl1
Where Inactive = '0' AND Role ='agent'
Order By LastName

I need for the last name, first name and office number to be displayed in the dropdown list as 'Agent' but once the user chooses one I need for the 'Agent' "AssociateCell and Email to post to a new table. The query does not appear to be pulling the last two columns and I cannot figure out what I am  doing wrong. Any assistance would be greatly appreciated.
Question by:jdines
    LVL 73

    Expert Comment

    the syntax is correct - that query will return 3 columns  Agent,  AssociateCell,  Email.

    if you run that query in studio  it doesn't do that?

    if it does, then the problem must be something in your app code that binds the query to the list

    Author Comment

    Yes it runs correctly in studio, I think the problem is that once I retreive the AssociateCell and Email I don't have it posted anywhere on the form so a hidden input field is required, am I on the right track?  
    LVL 73

    Accepted Solution

    probably, it'll depend entirely on the application language/framework used.

    if you need to pursue that, then I suggest opening a new question in whatever zones are appropriate to your gui environment

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now