Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

create table by using select command return data? Expand / Collapse
Author
Message
Posted Wednesday, October 24, 2012 3:13 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 11:56 PM
Points: 1,015, Visits: 2,840

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
Post #1376372
Posted Wednesday, October 24, 2012 3:24 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 3:59 AM
Points: 1,938, Visits: 1,149
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)
Post #1376377
Posted Wednesday, October 24, 2012 3:39 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 11:56 PM
Points: 1,015, Visits: 2,840
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,

Post #1376387
Posted Wednesday, October 24, 2012 3:48 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, April 08, 2014 4:52 AM
Points: 115, Visits: 138
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 ..............
Post #1376389
Posted Wednesday, October 24, 2012 4:06 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, April 04, 2014 5:29 AM
Points: 967, Visits: 396
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...


Post #1376394
Posted Wednesday, October 24, 2012 4:21 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 3:59 AM
Points: 1,938, Visits: 1,149
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)
Post #1376398
Posted Wednesday, October 24, 2012 4:35 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 11:56 PM
Points: 1,015, Visits: 2,840
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')


Post #1376403
Posted Wednesday, October 24, 2012 7:04 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, January 16, 2013 4:23 PM
Points: 415, Visits: 2,333
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')

Post #1376450
Posted Wednesday, October 24, 2012 7:38 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 3:59 AM
Points: 1,938, Visits: 1,149
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)
Post #1376474
Posted Wednesday, October 24, 2012 7:52 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, April 08, 2014 4:52 AM
Points: 115, Visits: 138
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')



Post #1376491
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse