Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create table from another table with additional columns in sql
Posted

1 solution

Something like this:

SELECT  [Statecode]
      ,[state]
  FROM [scott_test].[dbo].[test]
  
Statecode	state
1	DLI
2	MH
3	UP
2	DLI  
  
select 
 statecode, state, CAST (0 as integer) as new_column
into #states
from [scott_test].[dbo].[test];

select * from #states;

statecode	state	new_column
1	DLI	0
2	MH	0
3	UP	0
2	DLI	0


You often need to use CAST/CONVERT to get the new column to be the desired datatype.
Scott
 
Share this answer
 
Comments
Parmod Jangra 19-Dec-13 9:12am    
Thanks Scott

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900