[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Add a column with default value while creating the new table

Posted on 2012-09-02
3
Medium Priority
?
553 Views
Last Modified: 2012-09-21
I am using the following query statement.  I need to add an additional flag column to the new table "CLMU1" with a default value of "1" for each line that is created in the new table.

 

SELECT     CLDISPENSE.COMPANY, CLDISPENSE.SSNO, CLDISPENSE.FACILITY, CLDISPENSE.INTERNAL, CLDRCRED.DOCTOR, CLDISPENSE.DISPENSEDATE, CLDISPENSE.NOTE
INTO            CLMU1
FROM         CLDISPENSE LEFT OUTER JOIN
                      CLDRCRED ON CLDISPENSE.COMPANY = CLDRCRED.COMPANY AND CLDISPENSE.USERCODE = CLDRCRED.PROVID
0
Comment
Question by:Danean
3 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 2000 total points
ID: 38359102
Try this:
SELECT CLDISPENSE.COMPANY, CLDISPENSE.SSNO, CLDISPENSE.FACILITY, CLDISPENSE.INTERNAL, CLDRCRED.DOCTOR, CLDISPENSE.DISPENSEDATE, CLDISPENSE.NOTE, 1 AS NameOfFlag
INTO CLMU1
FROM CLDISPENSE LEFT OUTER JOIN CLDRCRED ON CLDISPENSE.COMPANY = CLDRCRED.COMPANY AND CLDISPENSE.USERCODE = CLDRCRED.PROVID

Open in new window

0
 

Author Comment

by:Danean
ID: 38359115
Thank you.  Perfect!!
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 38360033
You can use default constraint. Please do refer the link:

http://blog.sqlauthority.com/2011/04/09/sql-server-add-new-column-with-default-value/
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

830 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