Define column during selection and populate with fixed value

Posted on 2011-10-24
Last Modified: 2012-06-27
Hi All,

I'm sure this is pretty straight forward but I don't even know what key words to put in the search to be able to search for what I'm looking for.

Basically, I want to select some columns in a table. But I also want to add a column to this query and add a fixed value (the column is not in the table) i.e. the column I want to add is called 'Data Code' and the fixed value I want in that field is called 'UK'.

This just saves me from having to manually add the column and value in Excel once I've exported the data.

This not alias.



Question by:onesegun
    LVL 22

    Accepted Solution

    SELECT Field1, Field2, 'UK' as  'Data Code' from table_name
    LVL 9

    Assisted Solution

    Try this

    select Col1, Col2, 'UK' [Data Code] from TableName

    Open in new window


    Author Closing Comment


    Cheers guys.

    It was one of those things where it was pretty simple but I couldn't even figure out how to search for it

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
    Via a live example, show how to shrink a transaction log file down to a reasonable size.

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now