Define column during selection and populate with fixed value

Posted on 2011-10-24
Medium Priority
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

Om Prakash earned 100 total points
ID: 37017168
SELECT Field1, Field2, 'UK' as  'Data Code' from table_name

Assisted Solution

sachinpatil10d earned 100 total points
ID: 37017180
Try this

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

Open in new window


Author Closing Comment

ID: 37017243

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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

839 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