Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


create table by using select command return data?


create table by using select command return data?

Author
Message
SQL Galaxy
SQL Galaxy
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1220 Visits: 3465
How to create table by using select command return data.

Export utility not possible to create another data with table due to duplicate datab in tables.

select status, * from tbl_contract_emp_master TR inner join TBL_IRIS_IMAGES_MASTER tm on tr.guid=tm.guid and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')

thanks
ananda
malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2015 Visits: 1189
select status, *
into NewTable from tbl_contract_emp_master TR inner join
TBL_IRIS_IMAGES_MASTER tm on tr.guid=tm.guid
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')

select * from NewTable

Malleswarareddy
I.T.Analyst
MCITP(70-451)
SQL Galaxy
SQL Galaxy
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1220 Visits: 3465
error

Msg 2705, Level 16, State 3, Line 1
Column names in each table must be unique. Column name 'STATUS' in table 'NewTable' is specified more than once.


1.

[TBL_IRIS_IMAGES_MASTER]

[GUID] [varchar](50) NOT NULL,
[LEFT_IMAGE] [image] NULL,
[RIGHT_IMAGE] [image] NULL,
[IMAGE_FORMAT] [varchar](20) NULL,
[DEVICE_ID] [varchar](20) NULL,
[ENROLLTIME] [datetime] NULL,
[OPERATORID] [int] NULL


2.
[TBL_CONTRACT_EMP_MASTER]

[ID] [numeric](18, 0) NOT NULL,
[GUID] [varchar](50) NULL,
[EP_NO] [varchar](20) NULL,
[NAME] [varchar](200) NULL,
[CONTRACTOR_CODE] [varchar](50) NULL,
[CONTRACTOR_NAME] [varchar](200) NULL,
[SUBCONTRACTOR_NAME] [varchar](200) NULL,
[PLANT_CD] [varchar](50) NULL,
[SKILLCODE] [varchar](50) NULL,
[WORK_AREA] [varchar](50) NULL,
[DISCIPLINE] [varchar](50) NULL,
[PASSTYPE] [varchar](50) NULL,
[PRES_ADD] [varchar](200) NULL,
[PRES_VILLAGE] [varchar](100) NULL,
[PRES_TALUKA] [varchar](100) NULL,
[PRES_DISTRICT] [varchar](100) NULL,
[PRES_TEHSIL] [varchar](100) NULL,
[PRES_CITY] [varchar](75) NULL,
[PRES_STATE] [varchar](50) NULL,
[PRES_PIN] [varchar](15) NULL,
[PRES_TEL_NO] [varchar](50) NULL,
[FATHER_HUS_NAME] [varchar](100) NULL,
[DT_BIRTH] [datetime] NULL,
[DT_JOIN] [datetime] NULL,
[EP_VALID_TILL] [datetime] NULL,
[LICENSE_NO] [varchar](50) NULL,
[GENDER] [varchar](10) NULL,
[BLOOD_GROUP] [varchar](10) NULL,
[RELIGION_CD] [varchar](50) NULL,
[ID_MARK] [varchar](150) NULL,
[HEIGHT] [smallint] NULL,
[DT_LEAVE] [datetime] NULL,
[STATUS] [char](1) NULL,
[COMMENT] [varchar](200) NULL,
[ENROLLTIME] [datetime] NULL,
[OPERATORID] [int] NULL,
[MODIFY_DT] [datetime] NULL,
[CONTRACTOR_TYPE] [varchar](80) NULL,
[WORKAREA_CATEGORY] [varchar](50) NULL,


EamonSQL
EamonSQL
SSC-Enthusiastic
SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)

Group: General Forum Members
Points: 122 Visits: 181
you'll need to specify each column in the select statement and for the dupe column names use AS to rename.

eg

SELECT
a.dupe_col as dupe_col_1
,b.dupe_col as dupe_col_2
from tableA a
join tableB b on ..............
ThomasRushton
ThomasRushton
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: Moderators
Points: 1842 Visits: 2202
Just change the name of the first "Status" field that you are returning to something else. It's not a field from a table, so it's already a name you've created...
malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2015 Visits: 1189
You mentioned status field explicitly in select query and put * so there is already one status is filed there.so please remove first status.

This query will execute sucessfully


IF EXISTS(SELECT 1 FROM sys.objects where name='NewTable' and type='U')
begin
DROP TABLE NewTable
end
GO
select *
into NewTable from tbl_contract_emp_master TR inner join
TBL_IRIS_IMAGES_MASTER tm on tr.guid=tm.guid
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')

Malleswarareddy
I.T.Analyst
MCITP(70-451)
SQL Galaxy
SQL Galaxy
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1220 Visits: 3465
sorry Boss, the same error come again

I m using SQL 2K8 R2 64 bit-version.



IF EXISTS(SELECT 1 FROM sys.objects where name='NewTable' and type='U')
begin
DROP TABLE NewTable
end
GO
select *
into NewTable from tbl_contract_emp_master TR inner join
TBL_IRIS_IMAGES_MASTER tm on tr.guid=tm.guid
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')

Erorr

Msg 2705, Level 16, State 3, Line 1
Column names in each table must be unique. Column name 'GUID' in table 'NewTable' is specified more than once.




this below code working fine, but not able to create table New Table

select tr.[GUID]as gid,[EP_NO],[NAME],
[CONTRACTOR_CODE], [CONTRACTOR_NAME],
[SUBCONTRACTOR_NAME],[PLANT_CD],[SKILLCODE],[WORK_AREA],
[DISCIPLINE],[PASSTYPE],[PRES_ADD],[PRES_VILLAGE],
[PRES_TALUKA],[PRES_DISTRICT],[PRES_TEHSIL],[PRES_CITY],
[PRES_STATE],[PRES_PIN],[PRES_TEL_NO],[FATHER_HUS_NAME],
[DT_BIRTH],[DT_JOIN],[EP_VALID_TILL],[LICENSE_NO],
[GENDER],[BLOOD_GROUP],[RELIGION_CD],[ID_MARK],[HEIGHT],
[DT_LEAVE],[COMMENT],[STATUS],tr.[ENROLLTIME] as EntTime,
tr.[OPERATORID] as OptID, [MODIFY_DT],[CONTRACTOR_TYPE],[WORKAREA_CATEGORY]
from TBL_CONTRACT_EMP_MASTER TR
inner join
TBL_IRIS_IMAGES_MASTER tm on tr.[GUID]=tm.[GUID]
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')


patrickmcginnis59
patrickmcginnis59
SSC-Addicted
SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)

Group: General Forum Members
Points: 431 Visits: 2333
Just a suggestion to try, I can't tell if you tried something like this or not:


select tr.[GUID]as gid,[EP_NO],[NAME],
[CONTRACTOR_CODE], [CONTRACTOR_NAME],
[SUBCONTRACTOR_NAME],[PLANT_CD],[SKILLCODE],[WORK_AREA],
[DISCIPLINE],[PASSTYPE],[PRES_ADD],[PRES_VILLAGE],
[PRES_TALUKA],[PRES_DISTRICT],[PRES_TEHSIL],[PRES_CITY],
[PRES_STATE],[PRES_PIN],[PRES_TEL_NO],[FATHER_HUS_NAME],
[DT_BIRTH],[DT_JOIN],[EP_VALID_TILL],[LICENSE_NO],
[GENDER],[BLOOD_GROUP],[RELIGION_CD],[ID_MARK],[HEIGHT],
[DT_LEAVE],[COMMENT],[STATUS],tr.[ENROLLTIME] as EntTime,
tr.[OPERATORID] as OptID, [MODIFY_DT],[CONTRACTOR_TYPE],[WORKAREA_CATEGORY]
-------------------------- put the 'into' here --------------------------------- <<<<<<<<<<<<<<<<<<
INTO NEW_TABLE_NAME_HERE
-------------------------- end new text -------------------------------------- <<<<<<<<<<<<<<<<<<
from TBL_CONTRACT_EMP_MASTER TR
inner join
TBL_IRIS_IMAGES_MASTER tm on tr.[GUID]=tm.[GUID]
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')


malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2015 Visits: 1189
ananda.murugesan (10/24/2012)
sorry Boss, the same error come again

I m using SQL 2K8 R2 64 bit-version.



IF EXISTS(SELECT 1 FROM sys.objects where name='NewTable' and type='U')
begin
DROP TABLE NewTable
end
GO
select *
into NewTable from tbl_contract_emp_master TR inner join
TBL_IRIS_IMAGES_MASTER tm on tr.guid=tm.guid
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')

Erorr

Msg 2705, Level 16, State 3, Line 1
Column names in each table must be unique. Column name 'GUID' in table 'NewTable' is specified more than once.




this below code working fine, but not able to create table New Table

select tr.[GUID]as gid,[EP_NO],[NAME],
[CONTRACTOR_CODE], [CONTRACTOR_NAME],
[SUBCONTRACTOR_NAME],[PLANT_CD],[SKILLCODE],[WORK_AREA],
[DISCIPLINE],[PASSTYPE],[PRES_ADD],[PRES_VILLAGE],
[PRES_TALUKA],[PRES_DISTRICT],[PRES_TEHSIL],[PRES_CITY],
[PRES_STATE],[PRES_PIN],[PRES_TEL_NO],[FATHER_HUS_NAME],
[DT_BIRTH],[DT_JOIN],[EP_VALID_TILL],[LICENSE_NO],
[GENDER],[BLOOD_GROUP],[RELIGION_CD],[ID_MARK],[HEIGHT],
[DT_LEAVE],[COMMENT],[STATUS],tr.[ENROLLTIME] as EntTime,
tr.[OPERATORID] as OptID, [MODIFY_DT],[CONTRACTOR_TYPE],[WORKAREA_CATEGORY]
from TBL_CONTRACT_EMP_MASTER TR
inner join
TBL_IRIS_IMAGES_MASTER tm on tr.[GUID]=tm.[GUID]
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')









sorry Boss, the same error come again

I m using SQL 2K8 R2 64 bit-version.



IF EXISTS(SELECT 1 FROM sys.objects where name='NewTable' and type='U')
begin
DROP TABLE NewTable
end
GO
select *
into NewTable from tbl_contract_emp_master TR inner join
TBL_IRIS_IMAGES_MASTER tm on tr.guid=tm.guid
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')

Erorr

Msg 2705, Level 16, State 3, Line 1
Column names in each table must be unique. Column name 'GUID' in table 'NewTable' is specified more than once.


this below code working fine, but not able to create table New Table


select tr.[GUID]as gid,[EP_NO],[NAME],
[CONTRACTOR_CODE], [CONTRACTOR_NAME],
[SUBCONTRACTOR_NAME],[PLANT_CD],[SKILLCODE],[WORK_AREA],
[DISCIPLINE],[PASSTYPE],[PRES_ADD],[PRES_VILLAGE],
[PRES_TALUKA],[PRES_DISTRICT],[PRES_TEHSIL],[PRES_CITY],
[PRES_STATE],[PRES_PIN],[PRES_TEL_NO],[FATHER_HUS_NAME],
[DT_BIRTH],[DT_JOIN],[EP_VALID_TILL],[LICENSE_NO],
[GENDER],[BLOOD_GROUP],[RELIGION_CD],[ID_MARK],[HEIGHT],
[DT_LEAVE],[COMMENT],[STATUS],tr.[ENROLLTIME] as EntTime,
tr.[OPERATORID] as OptID, [MODIFY_DT],[CONTRACTOR_TYPE],[WORKAREA_CATEGORY]
INTO newTABLE
from TBL_CONTRACT_EMP_MASTER TR
inner join
TBL_IRIS_IMAGES_MASTER tm on tr.[GUID]=tm.[GUID]
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')

Because you error guid column name is TBL_CONTRACT_EMP_MASTER,TBL_CONTRACT_EMP_MASTER
so you are getting this erro use.alias name if there is same column name in different tables.

Malleswarareddy
I.T.Analyst
MCITP(70-451)
EamonSQL
EamonSQL
SSC-Enthusiastic
SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)SSC-Enthusiastic (122 reputation)

Group: General Forum Members
Points: 122 Visits: 181
shouldn't it be this?

If you're still getting problems run it with the table getting created with one column, then run it so it gets created with two columns, then three etc etc


IF EXISTS(SELECT 1 FROM sys.objects where name='NewTable' and type='U')
begin
DROP TABLE NewTable
end
GO
select tr.[GUID]as gid,[EP_NO],[NAME],
[CONTRACTOR_CODE], [CONTRACTOR_NAME],
[SUBCONTRACTOR_NAME],[PLANT_CD],[SKILLCODE],[WORK_AREA],
[DISCIPLINE],[PASSTYPE],[PRES_ADD],[PRES_VILLAGE],
[PRES_TALUKA],[PRES_DISTRICT],[PRES_TEHSIL],[PRES_CITY],
[PRES_STATE],[PRES_PIN],[PRES_TEL_NO],[FATHER_HUS_NAME],
[DT_BIRTH],[DT_JOIN],[EP_VALID_TILL],[LICENSE_NO],
[GENDER],[BLOOD_GROUP],[RELIGION_CD],[ID_MARK],[HEIGHT],
[DT_LEAVE],[COMMENT],[STATUS],tr.[ENROLLTIME] as EntTime,
tr.[OPERATORID] as OptID, [MODIFY_DT],[CONTRACTOR_TYPE],[WORKAREA_CATEGORY]
into NewTable from tbl_contract_emp_master TR inner join
from TBL_CONTRACT_EMP_MASTER TR
inner join
TBL_IRIS_IMAGES_MASTER tm on tr.[GUID]=tm.[GUID]
and EP_NO in ('104536884','104541256','104564417','t12035676','104567770','104556221','104567536')




Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search